2424import numpy as np
2525import pandas as pd
2626
27- from foqus_lib .framework .sdoe import df_utils , order
28-
29-
30- def test_mat2tuples ():
31- """Test mat2tuples"""
32- arr = np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]])
33- lte = order .mat2tuples (arr )
34- assert lte == [(1 , 0 , 4 ), (2 , 0 , 7 ), (2 , 1 , 8 )]
27+ from foqus_lib .framework .sdoe import df_utils , sdoe
3528
3629
3730def test_rank ():
38- """Call to order .rank() using hard-coded data written to temp files"""
31+ """Call to sdoe .rank() using hard-coded data written to temp files"""
3932
4033 # candidate dataframe to write to cand file
4134 cand_df = pd .DataFrame (
@@ -137,11 +130,11 @@ def test_rank():
137130 dmat_fn = pl .Path (sys .path [0 ], "tmp_dmat.npy" )
138131 np .save (dmat_fn , dmat )
139132
140- # file name dict to be passed to order .rank()
133+ # file name dict to be passed to sdoe .rank()
141134 fnames = {"cand" : str (cand_fn ), "dmat" : str (dmat_fn )}
142135
143136 # Make the actual call
144- fname_ranked = order .rank (fnames )
137+ fname_ranked = sdoe .rank (fnames )
145138
146139 # Ranked results as a dataframe
147140 ret_ranked_df = df_utils .load (fname_ranked )
@@ -161,6 +154,50 @@ def test_rank():
161154 # Clean up tmp files
162155 cand_fn .unlink ()
163156 dmat_fn .unlink ()
164- pl .Path (fname_ranked ).unlink ()
157+
158+ assert test_results
159+
160+
161+ def test_order_blocks ():
162+ """Call to sdoe.order_blocks() using hard-coded data written to temp files"""
163+
164+ # candidate dataframe to write to cand file
165+ cand_df = pd .DataFrame (
166+ {
167+ "w" : [0.15 , 0.15 , 0.15 , 0.175 , 0.175 , 0.15 , 0.15 , 0.15 ],
168+ "G" : [2700 , 2500 , 2000 , 2500 , 2500 , 1500 , 1500 , 2000 ],
169+ "lldg" : [0.15 , 0.15 , 0.25 , 0.25 , 0.3 , 0.15 , 0.15 , 0.3 ],
170+ "L" : [10039 , 9060 , 7519 , 7358 , 6185 , 3100 , 3454 , 8529 ],
171+ }
172+ )
173+ cand_fn = pl .Path (sys .path [0 ], "tmp_cand.csv" )
174+ df_utils .write (cand_fn , cand_df )
175+
176+ # file name dict to be passed to sdoe.order_blocks()
177+ fnames = {"cand" : str (cand_fn )}
178+
179+ # difficulty list
180+ difficulty = ["Hard" , "Hard" , "Easy" , "Easy" ]
181+
182+ # Make the actual call
183+ fname_blocks = sdoe .order_blocks (fnames , difficulty )
184+
185+ # Ranked results as a dataframe
186+ ret_blocks_df = df_utils .load (fname_blocks )
187+
188+ # Expected ranked results as dataframe
189+ blocks_df = pd .DataFrame (
190+ {
191+ "w" : [0.15 , 0.15 , 0.15 , 0.15 , 0.15 , 0.15 , 0.175 , 0.175 ],
192+ "G" : [1500 , 1500 , 2000 , 2000 , 2500 , 2700 , 2500 , 2500 ],
193+ "lldg" : [0.15 , 0.15 , 0.25 , 0.3 , 0.15 , 0.15 , 0.25 , 0.3 ],
194+ "L" : [3100 , 3454 , 7519 , 8529 , 9060 , 10039 , 7358 , 6185 ],
195+ }
196+ )
197+
198+ test_results = ret_blocks_df .equals (blocks_df )
199+
200+ # Clean up tmp files
201+ cand_fn .unlink ()
165202
166203 assert test_results
0 commit comments