Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Apr 5, 2023
1 parent 0fd3b1b commit 0adc787
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ spec setup =
c4.to_vector . should_equal [Nothing, 1001, 1000, 1001]

Test.group prefix+"Table.cast" pending=(if setup.is_database.not then "Cast is not implemented in the in-memory backend yet.") <|
Test.specify "should cast the columns in-place and not reorder them" <|
Test.specify 'should cast the columns "in-place" and not reorder them' <|
t = table_builder [["X", [1, 2, 3000]], ["Y", [4, 5, 6]], ["Z", [7, 8, 9]], ["A", [True, False, True]]]
t2 = t.cast ["Z", "Y"] Value_Type.Char
t2.column_names . should_equal ["X", "Y", "Z", "A"]
Expand Down
14 changes: 12 additions & 2 deletions test/Table_Tests/src/Common_Table_Operations/Join/Union_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,18 @@ spec setup =
check_same <| t1.union [] keep_unmatched_columns=True
check_same <| t1.union [] match_columns=Match_Columns.By_Position keep_unmatched_columns=True

# TODO tests for merging varchar (currently not possible in in-memory, so Postgres only)
# TODO unit tests for `find_common_type` helper
Test.specify "should correctly unify text columns of various lengths" pending=(if setup.test_selection.fixed_length_text_columns.not then "Fixed-length Char columns are not supported by this backend.") <|
t1 = table_builder [["A", ["a", "b", "c"]]] . cast "A" (Value_Type.Char size=1 variable_length=False)
t2 = table_builder [["A", ["xyz", "abc", "def"]]] . cast "A" (Value_Type.Char size=3 variable_length=False)

t1.at "A" . value_type . should_equal (Value_Type.Char size=1 variable_length=False)
t2.at "A" . value_type . should_equal (Value_Type.Char size=3 variable_length=False)

t3 = t1.union t2
expect_column_names ["A"] t3
t3.at "A" . to_vector . should_equal ["a", "b", "c", "xyz", "abc", "def"]
t3.at "A" . value_type . is_text . should_be_true
t3.at "A" . value_type . variable_length . should_be_true

Test.specify "should find a common type that will fit the merged columns" <|
t1 = table_builder [["int+bool", [1, 2, 3]], ["int+float", [0, 1, 2]]]
Expand Down
35 changes: 35 additions & 0 deletions test/Table_Tests/src/Helpers/Value_Type_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from Standard.Base import all

import Standard.Table.Data.Type.Value_Type.Bits
import Standard.Table.Data.Type.Value_Type.Value_Type
import Standard.Table.Data.Type.Value_Type_Helpers

from Standard.Test import Test, Test_Suite
import Standard.Test.Extensions
Expand All @@ -27,4 +28,38 @@ spec =
Value_Type.Unsupported_Data_Type.to_display_text . should_equal "Unsupported_Data_Type"
(Value_Type.Unsupported_Data_Type "FOO-BAR").to_display_text . should_equal "Unsupported_Data_Type (FOO-BAR)"

Test.specify "should use correct in-memory logic to reconcile pairs of types for operations like union/iif" <|
Value_Type_Helpers.reconcile_types Value_Type.Boolean Value_Type.Boolean . should_equal Value_Type.Boolean
Value_Type_Helpers.reconcile_types Value_Type.Boolean Value_Type.Integer . should_equal Value_Type.Integer

Value_Type_Helpers.reconcile_types (Value_Type.Integer Bits.Bits_16) (Value_Type.Integer Bits.Bits_32) . should_equal (Value_Type.Integer Bits.Bits_32)
Value_Type_Helpers.reconcile_types (Value_Type.Float Bits.Bits_32) (Value_Type.Float Bits.Bits_32) . should_equal (Value_Type.Float Bits.Bits_32)
Value_Type_Helpers.reconcile_types (Value_Type.Float Bits.Bits_32) (Value_Type.Float Bits.Bits_64) . should_equal (Value_Type.Float Bits.Bits_64)

Value_Type_Helpers.reconcile_types Value_Type.Boolean Value_Type.Byte . should_equal Value_Type.Byte
Value_Type_Helpers.reconcile_types (Value_Type.Integer Bits.Bits_16) Value_Type.Byte . should_equal (Value_Type.Integer Bits.Bits_16)
# 64-bit floats are always used when unifying with integers
Value_Type_Helpers.reconcile_types (Value_Type.Float Bits.Bits_32) Value_Type.Byte . should_equal Value_Type.Float
Value_Type_Helpers.reconcile_types (Value_Type.Float Bits.Bits_32) Value_Type.Boolean . should_equal Value_Type.Float

Value_Type_Helpers.reconcile_types (Value_Type.Char 10 False) (Value_Type.Char 10 False) . should_equal (Value_Type.Char 10 False)
Value_Type_Helpers.reconcile_types (Value_Type.Char 10 False) (Value_Type.Char 10 True) . should_equal (Value_Type.Char 10 True)
Value_Type_Helpers.reconcile_types (Value_Type.Char 100 False) (Value_Type.Char 10 True) . should_equal (Value_Type.Char 100 True)
Value_Type_Helpers.reconcile_types (Value_Type.Char 10 False) (Value_Type.Char 15 False) . should_equal (Value_Type.Char 15 True)

Value_Type_Helpers.reconcile_types Value_Type.Date Value_Type.Date . should_equal Value_Type.Date
Value_Type_Helpers.reconcile_types Value_Type.Time Value_Type.Time . should_equal Value_Type.Time
Value_Type_Helpers.reconcile_types Value_Type.Date_Time Value_Type.Date_Time . should_equal Value_Type.Date_Time
## Mixing date and time leads to mixed, if the user wants to convert date to at-midnight timestamp or
date-time to just date, they need to do it explicitly.
Value_Type_Helpers.reconcile_types Value_Type.Date Value_Type.Date_Time . should_equal Value_Type.Mixed
Value_Type_Helpers.reconcile_types Value_Type.Time Value_Type.Date_Time . should_equal Value_Type.Mixed

Value_Type_Helpers.reconcile_types Value_Type.Float Value_Type.Integer . should_equal Value_Type.Float
Value_Type_Helpers.reconcile_types Value_Type.Char Value_Type.Integer . should_equal Value_Type.Mixed
Value_Type_Helpers.reconcile_types Value_Type.Float Value_Type.Char . should_equal Value_Type.Mixed
Value_Type_Helpers.reconcile_types Value_Type.Float Value_Type.Binary . should_equal Value_Type.Mixed
Value_Type_Helpers.reconcile_types Value_Type.Char Value_Type.Binary . should_equal Value_Type.Mixed
Value_Type_Helpers.reconcile_types Value_Type.Char Value_Type.Boolean . should_equal Value_Type.Mixed

main = Test_Suite.run_main spec

0 comments on commit 0adc787

Please sign in to comment.