Skip to content

Commit

Permalink
Fix Table and Column test for nothing values (#12205)
Browse files Browse the repository at this point in the history
* Red

* Fix tests

* rename

* Remove comment

* Fix tests
  • Loading branch information
AdRiley authored Feb 5, 2025
1 parent 10fe252 commit cfd8055
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
12 changes: 6 additions & 6 deletions test/Table_Tests/src/In_Memory/Table_Running_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,12 @@ add_specs suite_builder =
warnings.not_empty . should_be_false
group_builder.specify "Running min ignores NaN values and works with grouping and warns" <|
result = table.running Statistic.Minimum "Ticket Price" "Running" group_by=["Flight"]
expected_column = Column.from_vector "Running" [100.5, 100.5, Number.nan, 100.5, 73.77]
expected_column = Column.from_vector "Running" [100.5, 100.5, Nothing, 100.5, 73.77]
# | Flight | Passenger | Ticket Price | Running
#---+--------+-----------+--------------+-------------------------
# 0 | BA0123 | A | 100.5 | 100.5
# 1 | BA0123 | B | 575.99 | 100.5
# 2 | SG0456 | A | NaN | NaN
# 2 | SG0456 | A | NaN | Nothing
# 3 | BA0123 | C | NaN | 100.5
# 4 | SG0456 | E | 73.77 | 73.77
expected_table = table.zip expected_column
Expand All @@ -626,12 +626,12 @@ add_specs suite_builder =
w.rows.should_equal [2, 3]
group_builder.specify "Running max ignores NaN values and works with grouping and warns" <|
result = table.running Statistic.Maximum "Ticket Price" "Running" group_by=["Flight"]
expected_column = Column.from_vector "Running" [100.5, 575.99, Number.nan, 575.99, 73.77]
expected_column = Column.from_vector "Running" [100.5, 575.99, Nothing, 575.99, 73.77]
# | Flight | Passenger | Ticket Price | Running
#---+--------+-----------+--------------+-------------------------
# 0 | BA0123 | A | 100.5 | 100.5
# 1 | BA0123 | B | 575.99 | 575.99
# 2 | SG0456 | A | NaN | NaN
# 2 | SG0456 | A | NaN | Nothing
# 3 | BA0123 | C | NaN | 575.99
# 4 | SG0456 | E | 73.77 | 73.77
expected_table = table.zip expected_column
Expand All @@ -656,12 +656,12 @@ add_specs suite_builder =
w.rows.should_equal [2, 3]
group_builder.specify "Running mean ignores NaN values and works when first value is NaN and warns" <|
result = table.running Statistic.Mean "Ticket Price" "Running" group_by=["Flight"]
expected_column = Column.from_vector "Running" [100.5, 338.245, Number.nan, 338.245, 73.77]
expected_column = Column.from_vector "Running" [100.5, 338.245, Nothing, 338.245, 73.77]
# | Flight | Passenger | Ticket Price | Running
#---+--------+-----------+--------------+-------------------------
# 0 | BA0123 | A | 100.5 | 100.5
# 1 | BA0123 | B | 575.99 | 338.245
# 2 | SG0456 | A | NaN | NaN
# 2 | SG0456 | A | NaN | Nothing
# 3 | BA0123 | C | NaN | 338.245
# 4 | SG0456 | E | 73.77 | 73.77
expected_table = table.zip expected_column
Expand Down
12 changes: 6 additions & 6 deletions test/Table_Tests/src/Util.enso
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ column_should_equal_impl actual expected loc='' =
Panic.throw (Test_Failure_Error.Error "Expected column length "+expected.length.to_text+", but got "+actual.length.to_text+(display_loc loc)+'.')
if actual.value_type != expected.value_type then
Panic.throw (Test_Failure_Error.Error "Expected column type "+expected.value_type.to_text+", but got "+actual.value_type.to_text+(display_loc loc)+'.')
actual.zip expected a-> e->
if values_equal a e then
actual.zip expected skip_nothing=False a-> e->
if values_not_equal a e then
report_fail actual expected loc
_ -> Panic.throw (Test_Failure_Error.Error "Got a Column, but expected a "+expected.to_display_text+(display_loc loc)+'.')

## PRIVATE
values_equal a e =
values_not_equal a e =
a != e && (a.is_a Number && e.is_a Number && a.is_nan && e.is_nan).not

## PRIVATE
report_fail actual expected loc =
indexed = actual.zip (0.up_to actual.length) a-> i-> Pair.new a i
indexed.zip expected a-> e->
if values_equal a.first e then
indexed = actual.zip (0.up_to actual.length) skip_nothing=False a-> i-> Pair.new a i
indexed.zip expected skip_nothing=False a-> e->
if values_not_equal a.first e then
Panic.throw (Test_Failure_Error.Error "Column: "+actual.name+" differs at row "+a.second.to_text+'.\n\t Actual : '+a.first.to_text+'\n\t Expected: '+e.to_text+'\n\t'+(display_loc loc)+'.')

## PRIVATE
Expand Down
26 changes: 25 additions & 1 deletion test/Table_Tests/src/Util_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,35 @@ add_specs suite_builder =
actual_column = Column.from_vector "Col" [1, 2, 3, 4]
res = Panic.recover Test_Failure_Error (column_should_equal_impl actual_column expected_column "LOCATION_PATH")
res.catch.message.should_equal "Got a Column, but expected a 42 (at LOCATION_PATH)."
group_builder.specify "Two Columns Containg NaNs Are Equal" <|
group_builder.specify "Two Columns Containing NaNs Are Equal" <|
# This is somewhat of a special case, as NaN != NaN but for the purposes of testing we consider them equal
expected_column = Column.from_vector "Col" [1.0, 2.0, Number.nan]
actual_column = Column.from_vector "Col" [1.0, 2.0, Number.nan]
actual_column.should_equal expected_column
group_builder.specify "Two Columns Containing Nothing Are Equal" <|
expected_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
actual_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
actual_column.should_equal expected_column
group_builder.specify "Comparing to Actual Nothing Value should fail" <|
expected_column = Column.from_vector "Col" [1.0, 2.0, 3.0]
actual_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
res = Panic.recover Test_Failure_Error (column_should_equal_impl actual_column expected_column "LOCATION_PATH")
res.catch.message.should_equal 'Column: Col differs at row 2.\n\t Actual : Nothing\n\t Expected: 3.0\n\t (at LOCATION_PATH).'
group_builder.specify "Comparing to Expected Nothing Value should fail" <|
expected_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
actual_column = Column.from_vector "Col" [1.0, 2.0, 3.0]
res = Panic.recover Test_Failure_Error (column_should_equal_impl actual_column expected_column "LOCATION_PATH")
res.catch.message.should_equal 'Column: Col differs at row 2.\n\t Actual : 3.0\n\t Expected: Nothing\n\t (at LOCATION_PATH).'
group_builder.specify "Comparing to Actual Nothing Value to Expected NaN Value should fail" <|
expected_column = Column.from_vector "Col" [1.0, 2.0, Number.nan]
actual_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
res = Panic.recover Test_Failure_Error (column_should_equal_impl actual_column expected_column "LOCATION_PATH")
res.catch.message.should_equal 'Column: Col differs at row 2.\n\t Actual : Nothing\n\t Expected: NaN\n\t (at LOCATION_PATH).'
group_builder.specify "Comparing to Actual NaN Value to Expected Nothing Value should fail" <|
expected_column = Column.from_vector "Col" [1.0, 2.0, Nothing]
actual_column = Column.from_vector "Col" [1.0, 2.0, Number.nan]
res = Panic.recover Test_Failure_Error (column_should_equal_impl actual_column expected_column "LOCATION_PATH")
res.catch.message.should_equal 'Column: Col differs at row 2.\n\t Actual : NaN\n\t Expected: Nothing\n\t (at LOCATION_PATH).'

group_builder.specify "Two Tables Are Equal" <|
expected_table = Table.new [Column.from_vector "Col1" ["Quis", "custodiet", "ipsos", "custodes?"], Column.from_vector "Col2" ["Who", "guards", "the", "guards?"]]
Expand Down

0 comments on commit cfd8055

Please sign in to comment.