mirror of
https://github.com/enso-org/enso.git
synced 2024-11-27 06:32:30 +03:00
Other way tests in Table.
This commit is contained in:
parent
4811ba2957
commit
7bb9767921
@ -2,6 +2,7 @@ from Standard.Base import all
|
||||
import Standard.Base.Data.Time.Date
|
||||
|
||||
import Standard.Table
|
||||
import Standard.Table.Data.Column
|
||||
import Standard.Table.Io.File_Format
|
||||
import Standard.Test
|
||||
|
||||
@ -12,11 +13,9 @@ spec =
|
||||
c_party = ["Party", ["Conservative", "Conservative", "Labour", "Labour", "Conservative", "Conservative", "Conservative"]]
|
||||
c_name = ["Title", ["Margaret Thatcher", "John Major", "Tony Blair", "Gordon Brown", "David Cameron", "Theresa May", "Boris Johnson"]]
|
||||
c_from = ["From", [Date.new 1979 05 04, Date.new 1990 11 28, Date.new 1997 05 02, Date.new 2007 06 27, Date.new 2010 05 11, Date.new 2016 07 13, Date.new 2019 07 24]]
|
||||
c_to = ["To", [Date.new 1990-11-28, Date.new 1997-05-02, Date.new 2007-06-27, Date.new 2010-05-11, Date.new 2016-07-13, Date.new 2019-07-24, Date.new 2022-07-07]]
|
||||
c_to = ["To", [Date.new 1990 11 28, Date.new 1997 05 02, Date.new 2007 06 27, Date.new 2010 05 11, Date.new 2016 07 13, Date.new 2019 07 24, Date.new 2022 07 07]]
|
||||
expected = Table.new [c_number, c_party, c_name, c_from, c_to]
|
||||
|
||||
Test.group "Table can be created with dates" <|
|
||||
|
||||
Test.group "File.read (Delimited) should work with Dates" <|
|
||||
table = (Enso_Project.data / "prime_ministers.csv").read
|
||||
Test.specify "should be able to read in a table with dates" <|
|
||||
@ -24,9 +23,24 @@ spec =
|
||||
table.columns.map (.name) . should_equal ['Number','Party', 'Title', 'From', 'To']
|
||||
table.row_count.should_equal 7
|
||||
|
||||
Test.specify "should be able to get the year of the dates" <|
|
||||
Test.specify "should be able to treat a single value as a Date" <|
|
||||
from_column = table.at 'From'
|
||||
from_column.at 6 . year . should_equal 2019
|
||||
from_column.at 6 . should_equal (Date.new 2019 7 24)
|
||||
|
||||
Test.specify "should be able to compare columns and table" <|
|
||||
table.at 'Number' . should_equal (Column.from_vector c_number.first c_number.second)
|
||||
table.at 'Party' . should_equal (Column.from_vector c_party.first c_party.second)
|
||||
table.at 'Title' . should_equal (Column.from_vector c_name.first c_name.second)
|
||||
table.at 'From' . should_equal (Column.from_vector c_from.first c_from.second)
|
||||
table.at 'To' . should_equal (Column.from_vector c_to.first c_to.second)
|
||||
table.should_equal expected
|
||||
|
||||
Test.group "Should be able to serialise a table with Dates to Text" <|
|
||||
expected_text = (Enso_Project.data / "prime_ministers.csv").read_text
|
||||
|
||||
Test.specify "should serialise back to input" <|
|
||||
delimited = Text.from expected format=(File_Format.Delimited ",")
|
||||
delimited.should_equal expected_text
|
||||
|
||||
main = Test.Suite.run_main here.spec
|
||||
|
@ -1,6 +1,7 @@
|
||||
from Standard.Base import all
|
||||
|
||||
import Standard.Table
|
||||
import Standard.Table.Data.Column
|
||||
import Standard.Test
|
||||
|
||||
Table.Table.should_equal expected =
|
||||
@ -8,3 +9,8 @@ Table.Table.should_equal expected =
|
||||
that_cols = expected.columns
|
||||
self_cols.map .name . should_equal (that_cols.map .name)
|
||||
self_cols.map .to_vector . should_equal (that_cols.map .to_vector)
|
||||
|
||||
Column.Column.should_equal expected =
|
||||
self.name.should_equal expected.name
|
||||
self.length.should_equal expected.length
|
||||
self.to_vector.should_equal expected.to_vector
|
||||
|
Loading…
Reference in New Issue
Block a user