Skip to content

Commit

Permalink
Adding more tests to SDoE (#1225)
Browse files Browse the repository at this point in the history
* Tweaking test_plot_utils and test_sdoe. Adding test_df_utils

* clean up imports

---------

Co-authored-by: Keith Beattie <[email protected]>
Co-authored-by: Ludovico Bianchi <[email protected]>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 70f62e2 commit a80a7f1
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 6 deletions.
102 changes: 102 additions & 0 deletions foqus_lib/framework/sdoe/test/cand1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
__id,w,G,lldg,L
0,0.125,1000,0.1,3495
1,0.125,1000,0.15,3302
2,0.125,1000,0.2,3110
3,0.125,1000,0.2,3035
4,0.125,1000,0.25,3496
5,0.125,1000,0.25,4075
6,0.125,1000,0.25,4654
7,0.125,1000,0.3,3957
8,0.125,1000,0.3,5190
9,0.125,1000,0.3,6423
10,0.125,1500,0.1,3257
11,0.125,1500,0.15,3284
12,0.125,1500,0.15,3408
13,0.125,1500,0.15,3532
14,0.125,1500,0.15,3656
15,0.125,1500,0.2,3310
16,0.125,1500,0.2,3955
17,0.125,1500,0.2,4601
18,0.125,1500,0.2,5247
19,0.125,1500,0.25,3336
20,0.125,1500,0.25,4503
21,0.125,1500,0.25,5670
22,0.125,1500,0.25,6838
23,0.125,1500,0.3,3362
24,0.125,1500,0.3,5051
25,0.125,1500,0.3,6740
26,0.125,1500,0.3,8429
27,0.125,2000,0.1,3020
28,0.125,2000,0.1,3607
29,0.125,2000,0.1,4194
30,0.125,2000,0.1,4781
31,0.125,2000,0.15,3265
32,0.125,2000,0.15,4241
33,0.125,2000,0.15,5218
34,0.125,2000,0.15,6194
35,0.125,2000,0.2,3510
36,0.125,2000,0.2,4876
37,0.125,2000,0.2,6242
38,0.125,2000,0.2,7608
39,0.125,2000,0.25,3755
40,0.125,2000,0.25,5510
41,0.125,2000,0.25,7266
42,0.125,2000,0.25,9021
43,0.125,2000,0.3,4000
44,0.125,2000,0.3,6145
45,0.125,2000,0.3,8290
46,0.125,2000,0.3,10435
47,0.125,2500,0.1,4354
48,0.125,2500,0.1,5926
49,0.125,2500,0.1,7498
50,0.125,2500,0.15,3246
51,0.125,2500,0.15,5075
52,0.125,2500,0.15,6904
53,0.125,2500,0.15,8733
54,0.125,2500,0.2,3709
55,0.125,2500,0.2,5796
56,0.125,2500,0.2,7883
57,0.125,2500,0.2,9969
58,0.125,2500,0.25,4173
59,0.125,2500,0.25,6517
60,0.125,2500,0.25,8861
61,0.125,2500,0.25,11205
62,0.125,2500,0.3,4637
63,0.125,2500,0.3,7238
64,0.125,2500,0.3,9839
65,0.125,2700,0.1,4653
66,0.125,2700,0.1,6618
67,0.125,2700,0.1,8584
68,0.125,2700,0.15,3238
69,0.125,2700,0.15,5408
70,0.125,2700,0.15,7579
71,0.125,2700,0.15,9749
72,0.125,2700,0.2,3789
73,0.125,2700,0.2,6164
74,0.125,2700,0.2,8539
75,0.125,2700,0.2,10914
76,0.125,2700,0.25,4341
77,0.125,2700,0.25,6920
78,0.125,2700,0.25,9499
79,0.125,2700,0.3,4892
80,0.125,2700,0.3,7676
81,0.125,2700,0.3,10459
82,0.15,1000,0.2,3072
83,0.15,1000,0.2,3219
84,0.15,1000,0.2,3367
85,0.15,1000,0.25,3621
86,0.15,1000,0.25,4320
87,0.15,1000,0.25,5019
88,0.15,1000,0.3,4171
89,0.15,1000,0.3,5421
90,0.15,1000,0.3,6672
91,0.15,1500,0.15,3100
92,0.15,1500,0.15,3454
93,0.15,1500,0.15,3809
94,0.15,1500,0.15,4163
95,0.15,1500,0.2,3317
96,0.15,1500,0.2,4090
97,0.15,1500,0.2,4864
98,0.15,1500,0.2,5638
99,0.15,1500,0.25,3534
100,0.15,1500,0.25,4727
101 changes: 101 additions & 0 deletions foqus_lib/framework/sdoe/test/cand2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
__id,w,G,lldg,L
101,0.15,1500,0.25,5920
102,0.15,1500,0.25,7113
103,0.15,1500,0.3,3751
104,0.15,1500,0.3,5363
105,0.15,1500,0.3,6975
106,0.15,1500,0.3,8587
107,0.15,2000,0.1,3664
108,0.15,2000,0.1,4489
109,0.15,2000,0.1,5314
110,0.15,2000,0.15,3274
111,0.15,2000,0.15,4386
112,0.15,2000,0.15,5499
113,0.15,2000,0.15,6611
114,0.15,2000,0.2,3710
115,0.15,2000,0.2,5109
116,0.15,2000,0.2,6509
117,0.15,2000,0.2,7908
118,0.15,2000,0.25,4145
119,0.15,2000,0.25,5832
120,0.15,2000,0.25,7519
121,0.15,2000,0.25,9206
122,0.15,2000,0.3,4581
123,0.15,2000,0.3,6555
124,0.15,2000,0.3,8529
125,0.15,2000,0.3,10503
126,0.15,2500,0.1,4509
127,0.15,2500,0.1,6225
128,0.15,2500,0.1,7940
129,0.15,2500,0.15,3448
130,0.15,2500,0.15,5318
131,0.15,2500,0.15,7189
132,0.15,2500,0.15,9060
133,0.15,2500,0.2,4102
134,0.15,2500,0.2,6128
135,0.15,2500,0.2,8154
136,0.15,2500,0.2,10179
137,0.15,2500,0.25,4757
138,0.15,2500,0.25,6937
139,0.15,2500,0.25,9118
140,0.15,2500,0.25,11299
141,0.15,2500,0.3,5411
142,0.15,2500,0.3,7747
143,0.15,2500,0.3,10082
144,0.15,2700,0.1,4847
145,0.15,2700,0.1,6919
146,0.15,2700,0.1,8990
147,0.15,2700,0.15,3518
148,0.15,2700,0.15,5691
149,0.15,2700,0.15,7865
150,0.15,2700,0.15,10039
151,0.15,2700,0.2,4259
152,0.15,2700,0.2,6535
153,0.15,2700,0.2,8811
154,0.15,2700,0.2,11087
155,0.15,2700,0.25,5001
156,0.15,2700,0.25,7379
157,0.15,2700,0.25,9758
158,0.15,2700,0.3,5743
159,0.15,2700,0.3,8224
160,0.15,2700,0.3,10704
161,0.175,1000,0.2,3108
162,0.175,1000,0.2,3479
163,0.175,1000,0.2,3849
164,0.175,1000,0.25,3746
165,0.175,1000,0.25,4566
166,0.175,1000,0.25,5385
167,0.175,1000,0.3,3116
168,0.175,1000,0.3,4384
169,0.175,1000,0.3,5653
170,0.175,1000,0.3,6921
171,0.175,1500,0.1,3044
172,0.175,1500,0.1,3312
173,0.175,1500,0.15,3501
174,0.175,1500,0.15,4086
175,0.175,1500,0.15,4670
176,0.175,1500,0.2,3324
177,0.175,1500,0.2,4226
178,0.175,1500,0.2,5127
179,0.175,1500,0.2,6029
180,0.175,1500,0.25,3731
181,0.175,1500,0.25,4950
182,0.175,1500,0.25,6169
183,0.175,1500,0.25,7387
184,0.175,1500,0.3,4139
185,0.175,1500,0.3,5675
186,0.175,1500,0.3,7210
187,0.175,1500,0.3,8746
188,0.175,2000,0.1,3720
189,0.175,2000,0.1,4784
190,0.175,2000,0.1,5847
191,0.175,2000,0.15,3283
192,0.175,2000,0.15,4532
193,0.175,2000,0.15,5780
194,0.175,2000,0.15,7028
195,0.175,2000,0.2,3910
196,0.175,2000,0.2,5343
197,0.175,2000,0.2,6776
198,0.175,2000,0.2,8209
199,0.175,2000,0.25,4536
200,0.175,2000,0.25,6154
11 changes: 11 additions & 0 deletions foqus_lib/framework/sdoe/test/prev1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__id,w,G,lldg,L
201,0.175,2000,0.25,7772
202,0.175,2000,0.25,9390
203,0.175,2000,0.3,5162
204,0.175,2000,0.3,6965
205,0.175,2000,0.3,8768
206,0.175,2000,0.3,10571
207,0.175,2500,0.1,4664
208,0.175,2500,0.1,6523
209,0.175,2500,0.1,8382
210,0.175,2500,0.15,3650
11 changes: 11 additions & 0 deletions foqus_lib/framework/sdoe/test/prev2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__id,w,G,lldg,L
211,0.175,2500,0.15,5562
212,0.175,2500,0.15,7474
213,0.175,2500,0.15,9386
214,0.175,2500,0.2,4495
215,0.175,2500,0.2,6460
216,0.175,2500,0.2,8424
217,0.175,2500,0.2,10389
218,0.175,2500,0.25,5340
219,0.175,2500,0.25,7358
220,0.175,2500,0.25,9375
11 changes: 11 additions & 0 deletions foqus_lib/framework/sdoe/test/previous_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__id,w,G,lldg,L
990,0.125,1500,0.2,5247
991,0.125,2000,0.2,6242
992,0.125,2500,0.2,9969
993,0.125,2700,0.1,8584
994,0.125,2700,0.25,6920
995,0.15,1000,0.25,5019
996,0.15,1500,0.2,4864
997,0.15,2000,0.15,6611
998,0.15,2500,0.25,9118
999,0.175,2700,0.25,10016
76 changes: 76 additions & 0 deletions foqus_lib/framework/sdoe/test/test_df_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#################################################################################
# FOQUS Copyright (c) 2012 - 2024, by the software owners: Oak Ridge Institute
# for Science and Education (ORISE), TRIAD National Security, LLC., Lawrence
# Livermore National Security, LLC., The Regents of the University of
# California, through Lawrence Berkeley National Laboratory, Battelle Memorial
# Institute, Pacific Northwest Division through Pacific Northwest National
# Laboratory, Carnegie Mellon University, West Virginia University, Boston
# University, the Trustees of Princeton University, The University of Texas at
# Austin, URS Energy & Construction, Inc., et al. All rights reserved.
#
# Please see the file LICENSE.md for full copyright and license information,
# respectively. This file is also available online at the URL
# "https://github.com/CCSI-Toolset/FOQUS".
#################################################################################
from importlib import resources
from pathlib import Path

import pandas as pd

from foqus_lib.framework.sdoe.df_utils import write, load, merge, check


def test_write():
fname = "test_data.csv"
df = pd.DataFrame([(1, 1), (2, 2), (3, 3), (4, 4)])

write(fname, df)

obj = Path(fname)

test_results = obj.exists()

# Clean up
obj.unlink()

assert test_results


def test_load():
fname = "candidates_usf.csv"
copy_from_package(fname)

df = load(fname)

assert df is not None


def test_merge():
fnames = ["candidates_usf.csv", "previous_data.csv"]
for fname in fnames:
copy_from_package(fname)

df = merge(fnames)

assert df is not None


def test_check():
cfiles = ["cand1.csv", "cand2.csv"]
hfiles = ["prev1.csv", "prev2.csv"]

for cfile in cfiles:
copy_from_package(cfile)

for hfile in hfiles:
copy_from_package(hfile)

cand_df, hist_df = check(cfiles, hfiles)

assert cand_df is not None
assert hist_df is not None


def copy_from_package(file_name: str) -> None:
content = resources.read_text(__package__, file_name)
Path(file_name).write_text(content)
4 changes: 1 addition & 3 deletions foqus_lib/framework/sdoe/test/test_plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
from pathlib import Path
from unittest import mock

import matplotlib.pyplot as plt
import pandas as pd
import pytest

from foqus_lib.framework.sdoe import df_utils, nusf, plot_utils, sdoe
from foqus_lib.framework.sdoe import df_utils, nusf, plot_utils


@mock.patch("foqus_lib.framework.sdoe.plot_utils.plt")
Expand Down
Loading

0 comments on commit a80a7f1

Please sign in to comment.