Skip to content

Commit

Permalink
Some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Feb 9, 2022
1 parent e9b365d commit bd73d39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from Standard.Table.Data.Order_Rule as Order_Rule_Module import Order_Rule
from Standard.Table.Data.Column_Selector as Column_Selector_Module import Column_Selector, By_Index
from Standard.Table.Data.Sort_Method as Sort_Method_Module import Sort_Method
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
import Standard.Table.Data.Column_Mapping
import Standard.Table.Data.Position
import Standard.Base.Error.Warnings

Expand Down
3 changes: 3 additions & 0 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ type Table
use this argument, as it will be removed in the future.

> Example
Rename the first column to "FirstColumn"

table.rename_columns (Column_Mapping.By_Position ["FirstColumn"])
rename_columns : Column_Mapping -> Problem_Behavior -> Warnings.Warning_System -> Table
rename_columns (column_map=(Column_Mapping.By_Position ["Column"])) (on_problems=Report_Warning) (warnings=Warnings.default) =
new_names = Table_Helpers.rename_columns internal_columns=this.columns mapping=column_map on_problems=on_problems warnings=warnings
Expand Down
18 changes: 18 additions & 0 deletions test/Table_Tests/src/Common_Table_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Standard.Test.Problems
import Standard.Base.Error.Problem_Behavior
import Standard.Base.Error.Warnings
import Standard.Table.Data.Matching
import Standard.Table.Data.Column_Mapping
from Standard.Table.Data.Matching import Case_Insensitive
from Standard.Table.Error as Table_Errors import all
from Standard.Table.Data.Column_Selector as Column_Selector_Module import all
Expand Down Expand Up @@ -385,3 +386,20 @@ spec prefix table_builder supports_case_sensitive_columns =

Test.specify "should correctly handle various combinations of options" <|
expect_column_names ["foo_100", "foo_21", "foo_3", "Foo_2", "foo_1", "foo_001", "bar"] <| table.sort_columns (Sort_Method natural_order=True case_sensitive=Case_Insensitive order=Sort_Order.Descending)

Test.group prefix+"Table.rename_columns" <|
table =
col1 = ["alpha", Integer, [1,2,3]]
col2 = ["beta", Integer, [4,5,6]]
col3 = ["gamma", Integer, [16,17,18]]
col4 = ["delta", Integer, [19,20,21]]
table_builder [col1, col2, col3, col4]

Test.specify "should work as shown in the doc examples" <|
expect_column_names ["FirstColumn", "beta", "gamma", "delta"] <|
table.rename_columns (Column_Mapping.By_Position ["FirstColumn"])

Test.specify "should work by index" <|
map = Map.from_vector [[0, "FirstColumn"], [-2, "Another"]]
expect_column_names ["FirstColumn", "beta", "Another", "delta"] <|
table.rename_columns (Column_Mapping.By_Index map)

0 comments on commit bd73d39

Please sign in to comment.