mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
Refactor stdlib tests to the builder API (#8968)
Follow-up of #8890 Refactor the rest of the tests to the builder API (`Test_New`): - `Image_Tests` - `Geo_Tests` - `Google_Api_Test` - `Examples_Test` - `AWS_Tests` - `Meta_Test_Suite_Tests` - `Visualization_Tests` # Important Notes - Unrelated: Fix NPE in `File.new "/" . name`
This commit is contained in:
parent
784d06912f
commit
83fffd9c05
@ -75,7 +75,7 @@ type Suite
|
||||
group.pending.is_nothing.not
|
||||
groups_to_run = groups_with_matching_names.filter group->
|
||||
pending_groups.contains group . not
|
||||
assert (pending_groups.length <= groups_to_run.length)
|
||||
assert (pending_groups.length <= groups_with_matching_names.length)
|
||||
assert (groups_to_run.length <= groups_with_matching_names.length)
|
||||
assert (groups_with_matching_names.length <= self.groups.length)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Errors.Common import Uninitialized_State
|
||||
from Standard.Base.Runtime import State
|
||||
import project.Test_Result.Test_Result
|
||||
import project.Clue.Clue
|
||||
@ -101,7 +102,8 @@ type Test
|
||||
## PRIVATE
|
||||
enrich_message_with_clue : Text -> Text
|
||||
enrich_message_with_clue message =
|
||||
case State.get Clue of
|
||||
clue = Panic.catch Uninitialized_State (State.get Clue) handler=(_-> Nothing)
|
||||
case clue of
|
||||
Clue.Value add_clue -> add_clue message
|
||||
_ -> message
|
||||
|
||||
|
@ -235,7 +235,8 @@ public final class EnsoFile implements EnsoObject {
|
||||
@Builtin.Method(name = "name")
|
||||
@CompilerDirectives.TruffleBoundary
|
||||
public String getName() {
|
||||
return this.truffleFile.getName();
|
||||
var name = this.truffleFile.getName();
|
||||
return name == null ? "/" : name;
|
||||
}
|
||||
|
||||
@Builtin.Method(name = "size_builtin")
|
||||
|
@ -1,8 +1,10 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.S3_Spec
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
S3_Spec.spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
S3_Spec.add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
@ -5,13 +5,12 @@ import Standard.Base.Runtime.Ref.Ref
|
||||
from Standard.AWS import S3, AWS_Credential
|
||||
from Standard.AWS.Errors import AWS_SDK_Error, More_Records_Available, S3_Error, S3_Bucket_Not_Found
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
import enso_dev.Base_Tests.Network.Enso_Cloud.Cloud_Tests_Setup.Cloud_Tests_Setup
|
||||
from enso_dev.Base_Tests.Network.Enso_Cloud.Cloud_Tests_Setup import with_retries
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
bucket_name = "enso-data-samples"
|
||||
not_a_bucket_name = "not_a_bucket_enso"
|
||||
object_name = "Bus_Stop_Benches.geojson"
|
||||
@ -19,36 +18,36 @@ spec =
|
||||
sub_folder_name = "examples/folder 1/"
|
||||
api_pending = if Environment.get "AWS_ACCESS_KEY_ID" . is_nothing then "No Access Key found." else Nothing
|
||||
cloud_setup = Cloud_Tests_Setup.prepare
|
||||
can_list_buckets = S3.list_buckets.is_error.not
|
||||
can_list_objects = S3.list_objects bucket_name . contains object_name
|
||||
|
||||
Test.group "S3.parse_uri" <|
|
||||
Test.specify "parse bucket only uris" <|
|
||||
suite_builder.group "S3.parse_uri" group_builder->
|
||||
group_builder.specify "parse bucket only uris" <|
|
||||
S3.parse_uri "s3://" . should_equal (Pair.new "" "")
|
||||
S3.parse_uri "s3://asda" . should_equal (Pair.new "asda" "")
|
||||
S3.parse_uri "s3://banana/" . should_equal (Pair.new "banana" "")
|
||||
|
||||
Test.specify "parse full paths uris" <|
|
||||
group_builder.specify "parse full paths uris" <|
|
||||
S3.parse_uri "s3://banana/apple" . should_equal (Pair.new "banana" "apple")
|
||||
S3.parse_uri "s3://banana/apple/orange" . should_equal (Pair.new "banana" "apple/orange")
|
||||
|
||||
Test.specify "reject invalid urils" <|
|
||||
group_builder.specify "reject invalid urils" <|
|
||||
S3.parse_uri "asda" . should_equal Nothing
|
||||
S3.parse_uri "s3:///" . should_equal Nothing
|
||||
S3.parse_uri "s3:///apple/orange" . should_equal Nothing
|
||||
|
||||
buckets = Ref.new []
|
||||
Test.group "S3.list_buckets" pending=api_pending <|
|
||||
Test.specify "should be able to list buckets" <|
|
||||
suite_builder.group "S3.list_buckets" pending=api_pending group_builder->
|
||||
group_builder.specify "should be able to list buckets" <|
|
||||
bucket_list = S3.list_buckets . should_succeed
|
||||
buckets.put bucket_list
|
||||
if bucket_name != Nothing then bucket_list . should_contain bucket_name
|
||||
|
||||
Test.specify "should handle auth issues" <|
|
||||
group_builder.specify "should handle auth issues" <|
|
||||
S3.list_buckets (AWS_Credential.Profile "NoSuchProfile") . should_fail_with AWS_SDK_Error
|
||||
|
||||
Test.specify "should not work with invalid credentials" <|
|
||||
group_builder.specify "should not work with invalid credentials" <|
|
||||
S3.list_buckets (AWS_Credential.Key "foo" "bar") . should_fail_with S3_Error
|
||||
|
||||
Test.specify "should allow to use Enso secrets within credentials" pending=cloud_setup.pending <| cloud_setup.with_prepared_environment <|
|
||||
group_builder.specify "should allow to use Enso secrets within credentials" pending=cloud_setup.pending <| cloud_setup.with_prepared_environment <|
|
||||
secret_key_id = Enso_Secret.create "my_test_secret-AWS-keyid" (Environment.get "AWS_ACCESS_KEY_ID")
|
||||
secret_key_id.should_succeed
|
||||
Panic.with_finalizer secret_key_id.delete <|
|
||||
@ -60,15 +59,15 @@ spec =
|
||||
r2.should_be_a Vector
|
||||
|
||||
## Rest of tests need a functional S3 connection
|
||||
pending = if bucket_name.is_nothing then "No S3 bucket set." else if buckets.get.is_error then "S3 Access Failed." else if buckets.get.contains bucket_name then Nothing else "S3 Bucket Not Found."
|
||||
pending = if bucket_name.is_nothing then "No S3 bucket set." else if can_list_buckets.not then "S3 Access Failed." else Nothing
|
||||
|
||||
Test.group "S3.head (bucket)" pending=pending <|
|
||||
Test.specify "should be able to head a bucket" <|
|
||||
suite_builder.group "S3.head (bucket)" pending=pending group_builder->
|
||||
group_builder.specify "should be able to head a bucket" <|
|
||||
S3.head bucket_name . should_equal Map.empty
|
||||
S3.head not_a_bucket_name . should_fail_with S3_Bucket_Not_Found
|
||||
|
||||
Test.group "S3.read_bucket" pending=pending <|
|
||||
Test.specify "should be able to read bucket" <|
|
||||
suite_builder.group "S3.read_bucket" pending=pending group_builder->
|
||||
group_builder.specify "should be able to read bucket" <|
|
||||
objects_and_folders = S3.read_bucket bucket_name
|
||||
folders = objects_and_folders.first
|
||||
folders . should_contain folder_name
|
||||
@ -76,12 +75,12 @@ spec =
|
||||
objects = objects_and_folders.second
|
||||
objects . should_contain object_name
|
||||
|
||||
Test.specify "should be able to read sub folder" <|
|
||||
group_builder.specify "should be able to read sub folder" <|
|
||||
objects_and_folders = S3.read_bucket bucket_name folder_name
|
||||
folders = objects_and_folders.first
|
||||
folders . should_contain sub_folder_name
|
||||
|
||||
Test.specify "should attach a warning if not a complete list" <|
|
||||
group_builder.specify "should attach a warning if not a complete list" <|
|
||||
objects = S3.read_bucket bucket_name max_count=1
|
||||
|
||||
warnings = Warning.get_all objects
|
||||
@ -90,20 +89,18 @@ spec =
|
||||
warning = warnings.first
|
||||
warning.value.should_be_a More_Records_Available
|
||||
|
||||
Test.specify "should handle missing bucket gracefully" <|
|
||||
group_builder.specify "should handle missing bucket gracefully" <|
|
||||
S3.read_bucket not_a_bucket_name . should_fail_with S3_Bucket_Not_Found
|
||||
|
||||
Test.specify "should handle auth issues" <|
|
||||
group_builder.specify "should handle auth issues" <|
|
||||
S3.read_bucket bucket_name credentials=(AWS_Credential.Profile "NoSuchProfile") . should_fail_with AWS_SDK_Error
|
||||
|
||||
list = Ref.new []
|
||||
Test.group "S3.list_objects" pending=pending <|
|
||||
Test.specify "should be able to list objects" <|
|
||||
suite_builder.group "S3.list_objects" pending=pending group_builder->
|
||||
group_builder.specify "should be able to list objects" <|
|
||||
objects = S3.list_objects bucket_name
|
||||
objects . should_contain object_name
|
||||
list.put objects
|
||||
|
||||
Test.specify "should attach a warning if not a complete list" <|
|
||||
group_builder.specify "should attach a warning if not a complete list" <|
|
||||
objects = S3.list_objects bucket_name max_count=1
|
||||
|
||||
warnings = Warning.get_all objects
|
||||
@ -112,28 +109,28 @@ spec =
|
||||
warning = warnings.first
|
||||
warning.value.should_be_a More_Records_Available
|
||||
|
||||
Test.specify "should handle missing bucket gracefully" <|
|
||||
group_builder.specify "should handle missing bucket gracefully" <|
|
||||
S3.list_objects not_a_bucket_name . should_fail_with S3_Bucket_Not_Found
|
||||
|
||||
Test.specify "should handle auth issues" <|
|
||||
group_builder.specify "should handle auth issues" <|
|
||||
S3.list_objects bucket_name credentials=(AWS_Credential.Profile "NoSuchProfile") . should_fail_with AWS_SDK_Error
|
||||
|
||||
## These tests need a valid object, so check we found it within the bucket.
|
||||
pending_object = if pending.is_nothing.not then pending else
|
||||
if list.get.contains object_name then Nothing else
|
||||
if can_list_objects then Nothing else
|
||||
"Unable to find test object in bucket."
|
||||
|
||||
Test.group "S3.head (object)" pending=pending_object <|
|
||||
Test.specify "should be able to head an object" <|
|
||||
suite_builder.group "S3.head (object)" pending=pending_object group_builder->
|
||||
group_builder.specify "should be able to head an object" <|
|
||||
S3.head bucket_name object_name . should_succeed
|
||||
S3.head not_a_bucket_name object_name . should_fail_with No_Such_Key
|
||||
S3.head bucket_name "not_an_object" . should_fail_with No_Such_Key
|
||||
|
||||
Test.specify "should handle auth issues" <|
|
||||
group_builder.specify "should handle auth issues" <|
|
||||
S3.list_objects bucket_name object_name credentials=(AWS_Credential.Profile "NoSuchProfile") . should_fail_with AWS_SDK_Error
|
||||
|
||||
Test.group "S3.get_object" pending=pending_object <|
|
||||
Test.specify "should be able to get an object" <|
|
||||
suite_builder.group "S3.get_object" pending=pending_object group_builder->
|
||||
group_builder.specify "should be able to get an object" <|
|
||||
response = S3.get_object bucket_name object_name
|
||||
response.should_succeed
|
||||
response.decode_as_json.should_succeed
|
||||
@ -141,7 +138,11 @@ spec =
|
||||
S3.get_object not_a_bucket_name object_name . should_fail_with S3_Bucket_Not_Found
|
||||
S3.get_object bucket_name "not_an_object" . should_fail_with No_Such_Key
|
||||
|
||||
Test.specify "should handle auth issues" <|
|
||||
group_builder.specify "should handle auth issues" <|
|
||||
S3.get_object bucket_name object_name credentials=(AWS_Credential.Profile "NoSuchProfile") . should_fail_with AWS_SDK_Error
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -22,6 +22,11 @@ add_specs suite_builder =
|
||||
non_existent_file = File.new "does_not_exist.txt"
|
||||
|
||||
suite_builder.group "File Operations" group_builder->
|
||||
group_builder.specify "should get name of the root" <|
|
||||
root = File.new "/"
|
||||
root.name . is_nothing . should_be_false
|
||||
root.path . is_nothing . should_be_false
|
||||
|
||||
group_builder.specify "should allow creating a new file" <|
|
||||
path = sample_file.path
|
||||
File.new path
|
||||
|
@ -2,106 +2,106 @@ from Standard.Base import all
|
||||
|
||||
import Standard.Examples
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
# While we're lacking the ability to run the documentation examples
|
||||
# automatically (#1706), these tests at least check that each of the examples
|
||||
# executes without an error resulting.
|
||||
|
||||
spec = Test.group "Examples" <|
|
||||
Test.specify "should allow construction of Example_Error_Type" <|
|
||||
add_specs suite_builder = suite_builder.group "Examples" group_builder->
|
||||
group_builder.specify "should allow construction of Example_Error_Type" <|
|
||||
val = Examples.Example_Error_Type.Error "Oh, no! Something went wrong!"
|
||||
val.should_be_a Examples.Example_Error_Type.Error
|
||||
|
||||
Test.specify "should allow getting the examples data directory" <|
|
||||
group_builder.specify "should allow getting the examples data directory" <|
|
||||
dir = Examples.data_dir
|
||||
dir.exists.should_be_true
|
||||
|
||||
Test.specify "should allow getting an example CSV file" <|
|
||||
group_builder.specify "should allow getting an example CSV file" <|
|
||||
Examples.csv.exists.should_be_true
|
||||
|
||||
Test.specify "should allow getting an example XLS file" <|
|
||||
group_builder.specify "should allow getting an example XLS file" <|
|
||||
Examples.xls.exists.should_be_true
|
||||
|
||||
Test.specify "should allow getting an example XLSX file" <|
|
||||
group_builder.specify "should allow getting an example XLSX file" <|
|
||||
Examples.xlsx.exists.should_be_true
|
||||
|
||||
Test.specify "should provide access to the CSV path" <|
|
||||
group_builder.specify "should provide access to the CSV path" <|
|
||||
(Examples.csv_path.length > 0) . should_be_true
|
||||
|
||||
Test.specify "should provide access to a scratch file location" <|
|
||||
group_builder.specify "should provide access to a scratch file location" <|
|
||||
# It is deleted every time it is requested.
|
||||
Examples.scratch_file.exists.should_be_false
|
||||
|
||||
Test.specify "should provide access to a simple duration" <|
|
||||
group_builder.specify "should provide access to a simple duration" <|
|
||||
Examples.duration
|
||||
|
||||
Test.specify "should provide some basic JSON text" <|
|
||||
group_builder.specify "should provide some basic JSON text" <|
|
||||
Json.parse Examples.json_text
|
||||
|
||||
Test.specify "should provide some basic JSON" <|
|
||||
group_builder.specify "should provide some basic JSON" <|
|
||||
Examples.json
|
||||
|
||||
Test.specify "should provide a JSON object" <|
|
||||
group_builder.specify "should provide a JSON object" <|
|
||||
Examples.json_object
|
||||
|
||||
Test.specify "should provide a basic cons list" <|
|
||||
group_builder.specify "should provide a basic cons list" <|
|
||||
Examples.list.length . should_equal 3
|
||||
|
||||
Test.specify "should provide a basic KV map" <|
|
||||
group_builder.specify "should provide a basic KV map" <|
|
||||
Examples.map.size . should_equal 3
|
||||
|
||||
Test.specify "should provide a type with no methods" <|
|
||||
group_builder.specify "should provide a type with no methods" <|
|
||||
Examples.No_Methods.should_be_a Examples.No_Methods
|
||||
|
||||
Test.specify "should provide a no method error value" <|
|
||||
group_builder.specify "should provide a no method error value" <|
|
||||
Examples.no_such_method
|
||||
|
||||
Test.specify "should provide a dummy error type" <|
|
||||
group_builder.specify "should provide a dummy error type" <|
|
||||
Examples.My_Error.Error
|
||||
|
||||
Test.specify "should provide a method that throws an error" <|
|
||||
group_builder.specify "should provide a method that throws an error" <|
|
||||
Examples.throw_error.should_fail_with Examples.My_Error
|
||||
|
||||
Test.specify "should provide a method that throws a panic" <|
|
||||
group_builder.specify "should provide a method that throws a panic" <|
|
||||
Test.expect_panic_with Examples.throw_panic Examples.My_Error
|
||||
|
||||
Test.specify "should provide a URL for some geo data" <|
|
||||
group_builder.specify "should provide a URL for some geo data" <|
|
||||
(Examples.geo_data_url.length > 0) . should_be_true
|
||||
|
||||
Test.specify "should provide an HTTP response" <|
|
||||
group_builder.specify "should provide an HTTP response" <|
|
||||
Examples.get_response
|
||||
|
||||
Test.specify "should provide a response containing geo data" <|
|
||||
group_builder.specify "should provide a response containing geo data" <|
|
||||
Examples.get_geo_data
|
||||
|
||||
Test.specify "should provide an example URI" <|
|
||||
group_builder.specify "should provide an example URI" <|
|
||||
Examples.uri
|
||||
|
||||
Test.specify "should provide an image file" <|
|
||||
group_builder.specify "should provide an image file" <|
|
||||
Examples.image_file
|
||||
|
||||
Test.specify "should provide an image" <|
|
||||
group_builder.specify "should provide an image" <|
|
||||
Examples.image
|
||||
|
||||
Test.specify "should provide a matrix" <|
|
||||
group_builder.specify "should provide a matrix" <|
|
||||
Examples.matrix
|
||||
|
||||
Test.specify "should provide a silly function" <|
|
||||
group_builder.specify "should provide a silly function" <|
|
||||
Examples.add_1_to 4 . should_equal 5
|
||||
|
||||
Test.specify "should provide a boolean" <|
|
||||
group_builder.specify "should provide a boolean" <|
|
||||
Examples.get_boolean
|
||||
|
||||
Test.specify "should provide a simple json table" <|
|
||||
group_builder.specify "should provide a simple json table" <|
|
||||
Examples.simple_table_json
|
||||
Examples.simple_table_json_headers
|
||||
|
||||
Test.specify "should provide some geo_json" <|
|
||||
group_builder.specify "should provide some geo_json" <|
|
||||
Examples.geo_json
|
||||
|
||||
Test.specify "should provide various table columns" <|
|
||||
group_builder.specify "should provide various table columns" <|
|
||||
Examples.integer_column
|
||||
Examples.decimal_column
|
||||
Examples.bool_column_1
|
||||
@ -109,14 +109,18 @@ spec = Test.group "Examples" <|
|
||||
Examples.text_column_1
|
||||
Examples.text_column_2
|
||||
|
||||
Test.specify "should provide various example tables" <|
|
||||
group_builder.specify "should provide various example tables" <|
|
||||
Examples.inventory_table
|
||||
Examples.popularity_table
|
||||
Examples.transactions_table
|
||||
|
||||
Test.specify "should provide an example of a regex match" <|
|
||||
group_builder.specify "should provide an example of a regex match" <|
|
||||
match = Examples.match
|
||||
match.groups.length . should_equal 5
|
||||
match.named_groups.size . should_equal 2
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.Examples_Spec
|
||||
import project.Python_Examples_Spec
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
Examples_Spec.spec
|
||||
Python_Examples_Spec.spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
Examples_Spec.add_specs suite_builder
|
||||
Python_Examples_Spec.add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
polyglot java import java.lang.System as Java_System
|
||||
polyglot java import java.io.File as Java_File
|
||||
@ -80,8 +80,8 @@ rewrite_main_file dir =
|
||||
code . write main on_existing_file=Existing_File_Behavior.Overwrite
|
||||
|
||||
|
||||
spec = Test.group "Python Examples" <|
|
||||
Test.specify "Create Enso Project with numpy" pending=pending <|
|
||||
add_specs suite_builder = suite_builder.group "Python Examples" group_builder->
|
||||
group_builder.specify "Create Enso Project with numpy" pending=pending <|
|
||||
IO.println "==== Generating Enso Project ===="
|
||||
prj = create_new_enso_project
|
||||
IO.println "Project ready at "+prj.path
|
||||
@ -107,4 +107,8 @@ spec = Test.group "Python Examples" <|
|
||||
res.stdout.should_contain "array(["
|
||||
res.stdout.should_contain "])"
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -3,23 +3,23 @@ import Standard.Table.Data.Table.Table
|
||||
|
||||
import Standard.Geo
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
Test.group "Geo Points" <|
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Geo Points" group_builder->
|
||||
point = Geo.point 51.509865 -0.118092
|
||||
Test.specify "should be able to be created as a Table" <|
|
||||
group_builder.specify "should be able to be created as a Table" <|
|
||||
is_table = case point of
|
||||
_ : Table -> True
|
||||
_ -> False
|
||||
is_table . should_be_true
|
||||
Test.specify "should contain a latitude and longitude" <|
|
||||
group_builder.specify "should contain a latitude and longitude" <|
|
||||
point.at "latitude" . at 0 . should_equal 51.509865
|
||||
point.at "longitude" . at 0 . should_equal -0.118092
|
||||
point.at "elevation" . at 0 . should_equal 0
|
||||
|
||||
Test.group "GeoJSON to Table" <|
|
||||
suite_builder.group "GeoJSON to Table" group_builder->
|
||||
geo_json = Json.parse <| '''
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
@ -29,7 +29,7 @@ spec =
|
||||
]
|
||||
}
|
||||
|
||||
Test.specify "should allow converting a GeoJSON array of features into a table" <|
|
||||
group_builder.specify "should allow converting a GeoJSON array of features into a table" <|
|
||||
fields = ['foo', 'bar', 'baz', 'longitude', 'elevation']
|
||||
t = Geo.geo_json_to_table (geo_json.get "features") fields
|
||||
t.columns.map .name . should_contain_the_same_elements_as fields
|
||||
@ -39,7 +39,7 @@ spec =
|
||||
t.at 'longitude' . to_vector . should_equal [-118.58, 10.11]
|
||||
t.at 'elevation' . to_vector . should_equal [Nothing, 19]
|
||||
|
||||
Test.specify "should allow converting a GeoJSON object into a table with provided fields" <|
|
||||
group_builder.specify "should allow converting a GeoJSON object into a table with provided fields" <|
|
||||
fields = ['foo', 'bar', 'longitude']
|
||||
t = Geo.geo_json_to_table geo_json fields
|
||||
t.columns.map .name . should_contain_the_same_elements_as fields
|
||||
@ -47,7 +47,7 @@ spec =
|
||||
t.at 'bar' . to_vector . should_equal ['value2', Nothing]
|
||||
t.at 'longitude' . to_vector . should_equal [-118.58, 10.11]
|
||||
|
||||
Test.specify "should allow converting a GeoJSON object into a table containing all available fields" <|
|
||||
group_builder.specify "should allow converting a GeoJSON object into a table containing all available fields" <|
|
||||
fields = ['bar', 'baz', 'elevation', 'foo', 'latitude', 'longitude']
|
||||
t = Geo.geo_json_to_table geo_json
|
||||
t.columns.map .name . should_contain_the_same_elements_as fields
|
||||
|
@ -1,8 +1,11 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.Geo_Spec
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
Geo_Spec.spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
Geo_Spec.add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,15 +1,22 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Google_Api
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
|
||||
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
||||
add_specs suite_builder =
|
||||
secret = enso_project.data / 'secret.json'
|
||||
api = Google_Api.initialize secret
|
||||
|
||||
Test.group "Google Spreadsheets" <|
|
||||
|
||||
Test.specify "should allow downloading a spreadsheet" <|
|
||||
suite_builder.group "Google Spreadsheets" group_builder->
|
||||
group_builder.specify "should allow downloading a spreadsheet" <|
|
||||
sheet_id = '1WjVQhYdc04RwdWB22RNLgfQiLeWYhxiij1_xj22RDq0'
|
||||
sheet_range = 'Sheet1!A1:B6'
|
||||
table = api.spreadsheets.get_table sheet_id sheet_range
|
||||
|
@ -3,20 +3,20 @@ from Standard.Base import all
|
||||
from Standard.Image import Image, Matrix
|
||||
import Standard.Image.Data.Matrix_Error.Matrix_Error
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
Test.group "Image with 1 channel" <|
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Image with 1 channel" group_builder->
|
||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x]) rows=3 channels=1
|
||||
ones = Image.from_vector (Vector.fill 9 1 . flat_map x->[x]) rows=3 channels=1
|
||||
identity = Image.from_vector ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map x->[x]) rows=3 channels=1
|
||||
|
||||
Test.specify "should convert to a vector" <|
|
||||
group_builder.specify "should convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9 0)
|
||||
ones.to_vector . should_equal (Vector.fill 9 1)
|
||||
identity.to_vector . should_equal ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map x->[x])
|
||||
Test.specify "should convert to a matrix" <|
|
||||
group_builder.specify "should convert to a matrix" <|
|
||||
z = zeros.to_matrix
|
||||
z.rows . should_equal zeros.rows
|
||||
z.columns . should_equal zeros.columns
|
||||
@ -27,7 +27,7 @@ spec =
|
||||
o.columns . should_equal ones.columns
|
||||
o.channels . should_equal ones.channels
|
||||
o.to_vector . should_equal ones.to_vector
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1]
|
||||
identity.get 1 0 . should_equal [0]
|
||||
identity.get 1 1 . should_equal [1]
|
||||
@ -36,84 +36,84 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
ones+1 . should_equal ones
|
||||
identity+1 . should_equal ones
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Image.from_vector (Vector.fill 9 0.8) channels=1 rows=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
ones+[1, 1] . should_equal ones
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
(zeros + ones.to_matrix) . should_equal ones
|
||||
(ones + ones.to_matrix) . should_equal ones
|
||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal zeros
|
||||
zeros-1 . should_equal zeros
|
||||
ones-1 . should_equal zeros
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
zeros-[1] . should_equal zeros
|
||||
ones-[1, 1] . should_equal zeros
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
(zeros - ones.to_matrix) . should_equal zeros
|
||||
(ones - ones.to_matrix) . should_equal zeros
|
||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal ones
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[1, 1] . should_equal ones
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
(ones * zeros.to_matrix) . should_equal zeros
|
||||
(identity * ones.to_matrix) . should_equal identity
|
||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
ones/5 . should_equal (Image.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2] . should_equal zeros
|
||||
ones/[5, 5] . should_equal (Image.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
||||
identity/[] . should_equal zeros
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
fives = Matrix.from_vector (Vector.fill 9 5) channels=1 rows=3
|
||||
(ones / ones.to_matrix) . should_equal ones
|
||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Image with 2 channels" <|
|
||||
suite_builder.group "Image with 2 channels" group_builder->
|
||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x]) rows=3 channels=2
|
||||
ones = Image.from_vector (Vector.fill 9 1 . flat_map x->[x,x]) rows=3 channels=2
|
||||
identity = Image.from_vector ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map x->[x,0]) rows=3 channels=2
|
||||
Test.specify "should convert to a vector" <|
|
||||
group_builder.specify "should convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9*2 0)
|
||||
ones.to_vector . should_equal (Vector.fill 9*2 1)
|
||||
identity.to_vector . should_equal [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]
|
||||
Test.specify "should convert to a matrix" <|
|
||||
group_builder.specify "should convert to a matrix" <|
|
||||
z = zeros.to_matrix
|
||||
z.rows . should_equal zeros.rows
|
||||
z.columns . should_equal zeros.columns
|
||||
@ -124,7 +124,7 @@ spec =
|
||||
o.columns . should_equal ones.columns
|
||||
o.channels . should_equal ones.channels
|
||||
o.to_vector . should_equal ones.to_vector
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0]
|
||||
identity.get 1 0 . should_equal [0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0]
|
||||
@ -133,85 +133,85 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
ones+1 . should_equal ones
|
||||
identity+1 . should_equal ones
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Image.from_vector (Vector.fill 9*2 0.8) channels=2 rows=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
ones+[1, 1] . should_equal ones
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
(zeros + ones.to_matrix) . should_equal ones
|
||||
(ones + ones.to_matrix) . should_equal ones
|
||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal zeros
|
||||
zeros-1 . should_equal zeros
|
||||
ones-1 . should_equal zeros
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
zeros-[1] . should_equal zeros
|
||||
ones-[1, 1] . should_equal zeros
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
(zeros - ones.to_matrix) . should_equal zeros
|
||||
(ones - ones.to_matrix) . should_equal zeros
|
||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal ones
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[1, 1] . should_equal ones
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
(ones * zeros.to_matrix) . should_equal zeros
|
||||
(identity * ones.to_matrix) . should_equal identity
|
||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
ones/5 . should_equal (Image.from_vector (Vector.fill 9*2 0.2) channels=2 rows=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2] . should_equal zeros
|
||||
ones/[5, 5] . should_equal (Image.from_vector (Vector.fill 9*2 0.2) channels=2 rows=3)
|
||||
identity/[] . should_equal zeros
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
fives = Matrix.from_vector (Vector.fill 9*2 5) channels=2 rows=3
|
||||
(ones / ones.to_matrix) . should_equal ones
|
||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*2 0.2) channels=2 rows=3)
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Image with 3 channels" <|
|
||||
suite_builder.group "Image with 3 channels" group_builder->
|
||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x]) rows=3 channels=3
|
||||
ones = Image.from_vector (Vector.fill 9 1 . flat_map x->[x,x,x]) rows=3 channels=3
|
||||
identity = Image.from_vector ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map x->[x,0,0]) rows=3 channels=3
|
||||
|
||||
Test.specify "should convert to a vector" <|
|
||||
group_builder.specify "should convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9*3 0)
|
||||
ones.to_vector . should_equal (Vector.fill 9*3 1)
|
||||
identity.to_vector . should_equal [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
|
||||
Test.specify "should convert to a matrix" <|
|
||||
group_builder.specify "should convert to a matrix" <|
|
||||
z = zeros.to_matrix
|
||||
z.rows . should_equal zeros.rows
|
||||
z.columns . should_equal zeros.columns
|
||||
@ -222,7 +222,7 @@ spec =
|
||||
o.columns . should_equal ones.columns
|
||||
o.channels . should_equal ones.channels
|
||||
o.to_vector . should_equal ones.to_vector
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0]
|
||||
@ -231,85 +231,85 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
ones+1 . should_equal ones
|
||||
identity+1 . should_equal ones
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Image.from_vector (Vector.fill 9*3 0.8) channels=3 rows=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
ones+[1, 1] . should_equal ones
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
(zeros + ones.to_matrix) . should_equal ones
|
||||
(ones + ones.to_matrix) . should_equal ones
|
||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal zeros
|
||||
zeros-1 . should_equal zeros
|
||||
ones-1 . should_equal zeros
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
zeros-[1] . should_equal zeros
|
||||
ones-[1, 1, 1] . should_equal zeros
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
(zeros - ones.to_matrix) . should_equal zeros
|
||||
(ones - ones.to_matrix) . should_equal zeros
|
||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal ones
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[1, 1] . should_equal ones
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
(ones * zeros.to_matrix) . should_equal zeros
|
||||
(identity * ones.to_matrix) . should_equal identity
|
||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
ones/5 . should_equal (Image.from_vector (Vector.fill 9*3 0.2) channels=3 rows=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2] . should_equal zeros
|
||||
ones/[5, 5] . should_equal (Image.from_vector (Vector.fill 9*3 0.2) channels=3 rows=3)
|
||||
identity/[] . should_equal zeros
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
fives = Matrix.from_vector (Vector.fill 9*3 5) channels=3 rows=3
|
||||
(ones / ones.to_matrix) . should_equal ones
|
||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*3 0.2) channels=3 rows=3)
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Image with 4 channels" <|
|
||||
suite_builder.group "Image with 4 channels" group_builder->
|
||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x,x]) rows=3 channels=4
|
||||
ones = Image.from_vector (Vector.fill 9 1 . flat_map x->[x,x,x,x]) rows=3 channels=4
|
||||
identity = Image.from_vector ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map x->[x,0,0,0]) rows=3 channels=4
|
||||
|
||||
Test.specify "should convert to a vector" <|
|
||||
group_builder.specify "should convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9*4 0)
|
||||
ones.to_vector . should_equal (Vector.fill 9*4 1)
|
||||
identity.to_vector . should_equal [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
|
||||
Test.specify "should convert to a matrix" <|
|
||||
group_builder.specify "should convert to a matrix" <|
|
||||
z = zeros.to_matrix
|
||||
z.rows . should_equal zeros.rows
|
||||
z.columns . should_equal zeros.columns
|
||||
@ -320,7 +320,7 @@ spec =
|
||||
o.columns . should_equal ones.columns
|
||||
o.channels . should_equal ones.channels
|
||||
o.to_vector . should_equal ones.to_vector
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||
@ -329,73 +329,77 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
ones+1 . should_equal ones
|
||||
identity+1 . should_equal ones
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Image.from_vector (Vector.fill 9*4 0.8) channels=4 rows=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
ones+[1, 1] . should_equal ones
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
(zeros + ones.to_matrix) . should_equal ones
|
||||
(ones + ones.to_matrix) . should_equal ones
|
||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal zeros
|
||||
zeros-1 . should_equal zeros
|
||||
ones-1 . should_equal zeros
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
zeros-[1] . should_equal zeros
|
||||
ones-[1, 1, 1, 1] . should_equal zeros
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
(zeros - ones.to_matrix) . should_equal zeros
|
||||
(ones - ones.to_matrix) . should_equal zeros
|
||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal ones
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[1, 1] . should_equal ones
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
(ones * zeros.to_matrix) . should_equal zeros
|
||||
(identity * ones.to_matrix) . should_equal identity
|
||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
ones/5 . should_equal (Image.from_vector (Vector.fill 9*4 0.2) channels=4 rows=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2] . should_equal zeros
|
||||
ones/[5, 5] . should_equal (Image.from_vector (Vector.fill 9*4 0.2) channels=4 rows=3)
|
||||
identity/[] . should_equal zeros
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
fives = Matrix.from_vector (Vector.fill 9*4 5) channels=4 rows=3
|
||||
(ones / ones.to_matrix) . should_equal ones
|
||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*4 0.2) channels=4 rows=3)
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -3,42 +3,42 @@ from Standard.Base import all
|
||||
from Standard.Image import Matrix
|
||||
import Standard.Image.Data.Matrix_Error.Matrix_Error
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
Test.group "Matrix_Error" <|
|
||||
Test.specify "should display errors" <|
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Matrix_Error" group_builder->
|
||||
group_builder.specify "should display errors" <|
|
||||
(Matrix_Error.Index_Out_Of_Bounds 2 3 4).to_display_text . should_equal '''
|
||||
For a matrix with dimensions 2x3, the index 4 is out of bounds.
|
||||
Matrix_Error.Dimensions_Not_Equal.to_display_text . should_equal '''
|
||||
Dimensions are not equal.
|
||||
Test.group "Matrix with 1 channel" <|
|
||||
suite_builder.group "Matrix with 1 channel" group_builder->
|
||||
zeros = Matrix.zeros 3 3
|
||||
ones = Matrix.ones 3 3
|
||||
identity = Matrix.identity 3 3
|
||||
twos = Matrix.from_vector [2, 2, 2, 2, 2, 2, 2, 2, 2] . reshape rows=3 channels=1
|
||||
|
||||
Test.specify "should create from a vector" <|
|
||||
group_builder.specify "should create from a vector" <|
|
||||
Matrix.from_vector (Vector.fill 9 0) channels=1 rows=3 . should_equal zeros
|
||||
Matrix.from_vector (Vector.fill 9 1) channels=1 rows=3 . should_equal ones
|
||||
|
||||
Test.specify "should be able to reshape" <|
|
||||
group_builder.specify "should be able to reshape" <|
|
||||
Matrix.from_vector (Vector.fill 9 0) . reshape rows=3 . should_equal zeros
|
||||
Matrix.from_vector (Vector.fill 9 1) . reshape rows=3 channels=1 . should_equal ones
|
||||
|
||||
Test.specify "should be able to convert to a vector" <|
|
||||
group_builder.specify "should be able to convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9 0)
|
||||
ones.to_vector . should_equal (Vector.fill 9 1)
|
||||
identity.to_vector . should_equal [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
||||
|
||||
Test.specify "should allow normalizing values" <|
|
||||
group_builder.specify "should allow normalizing values" <|
|
||||
zeros.normalize . should_equal zeros
|
||||
ones.normalize . should_equal zeros
|
||||
identity.normalize . should_equal identity
|
||||
(Matrix.from_vector [0, 1, 2, 3, 4] channels=1).normalize . should_equal (Matrix.from_vector [0.0, 0.25, 0.5, 0.75, 1.0] channels=1)
|
||||
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1]
|
||||
identity.get 1 0 . should_equal [0]
|
||||
identity.get 1 1 . should_equal [1]
|
||||
@ -47,98 +47,98 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
ones+1 . should_equal twos
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Matrix.from_vector (Vector.fill 9 0.8) channels=1 rows=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
ones+[1, 1] . should_equal twos
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
zeros+ones . should_equal ones
|
||||
ones+ones . should_equal twos
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal zeros
|
||||
twos-1 . should_equal ones
|
||||
ones-0 . should_equal ones
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
ones-[1, 1] . should_equal zeros
|
||||
twos-[1, 1] . should_equal ones
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
ones-ones . should_equal zeros
|
||||
twos-ones . should_equal ones
|
||||
identity-zeros . should_equal identity
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal twos
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[2, 2] . should_equal twos
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
zeros*ones . should_equal zeros
|
||||
ones*twos . should_equal twos
|
||||
identity*zeros . should_equal zeros
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
twos/2 . should_equal ones
|
||||
ones/5 . should_equal (Matrix.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2] . should_equal zeros
|
||||
twos/[2, 2, 2, 2] . should_equal ones
|
||||
ones/[5, 5] . should_equal (Matrix.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
zeros/ones . should_equal zeros
|
||||
twos/twos . should_equal ones
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Matrix with 2 channels" <|
|
||||
suite_builder.group "Matrix with 2 channels" group_builder->
|
||||
zeros = Matrix.zeros 3 3 channels=2
|
||||
ones = Matrix.ones 3 3 channels=2
|
||||
identity = Matrix.identity 3 3 channels=2
|
||||
twos = Matrix.from_vector (ones.to_vector . map (_*2)) . reshape rows=3 channels=2
|
||||
|
||||
Test.specify "should create from a vector" <|
|
||||
group_builder.specify "should create from a vector" <|
|
||||
Matrix.from_vector zeros.to_vector rows=3 channels=2 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector rows=3 channels=2 . should_equal ones
|
||||
|
||||
Test.specify "should be able to reshape" <|
|
||||
group_builder.specify "should be able to reshape" <|
|
||||
Matrix.from_vector zeros.to_vector . reshape rows=3 channels=2 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector . reshape rows=3 channels=2 . should_equal ones
|
||||
|
||||
Test.specify "should be able to convert to a vector" <|
|
||||
group_builder.specify "should be able to convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9 [0, 0] . flat_map x->x)
|
||||
ones.to_vector . should_equal (Vector.fill 9 [1, 0] . flat_map x->x)
|
||||
identity.to_vector . should_equal ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map (x -> [x, 0]))
|
||||
|
||||
Test.specify "should allow normalizing values" <|
|
||||
group_builder.specify "should allow normalizing values" <|
|
||||
zeros.normalize . should_equal zeros
|
||||
ones.normalize . should_equal ones
|
||||
identity.normalize . should_equal identity
|
||||
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0]
|
||||
identity.get 1 0 . should_equal [0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0]
|
||||
@ -147,101 +147,101 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*2 1) rows=3 channels=2)
|
||||
ones+1 . should_equal (Matrix.from_vector (ones.to_vector . map (+1)) rows=3 channels=2)
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Matrix.from_vector (Vector.fill 9*2 0.8) rows=3 channels=2)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
zeros+[1, 1] . should_equal (Matrix.from_vector (Vector.fill 9*2 1) rows=3 channels=2)
|
||||
ones+[1, 0] . should_equal twos
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
zeros+ones . should_equal ones
|
||||
ones+ones . should_equal twos
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=2)
|
||||
twos-1 . should_equal (Matrix.from_vector (twos.to_vector . map (_ - 1)) rows=3 channels=2)
|
||||
ones-0 . should_equal ones
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
ones-[1, 0] . should_equal zeros
|
||||
twos-[1, 0] . should_equal ones
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
ones-ones . should_equal zeros
|
||||
twos-ones . should_equal ones
|
||||
identity-zeros . should_equal identity
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal twos
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[2, 2] . should_equal twos
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
zeros*ones . should_equal zeros
|
||||
ones*twos . should_equal twos
|
||||
identity*zeros . should_equal zeros
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
twos/2 . should_equal ones
|
||||
ones/5 . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=2)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2, 1, 1, 1] . should_equal zeros
|
||||
twos/[2, 2, 2, 2] . should_equal ones
|
||||
ones/[5, 5, 5, 5] . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=2)
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
all_ones = ones.to_vector . map (_ -> 1)
|
||||
all_twos = twos.to_vector . map (_ -> 2)
|
||||
zeros/all_ones . should_equal zeros
|
||||
twos/all_twos . should_equal ones
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Matrix with 3 channels" <|
|
||||
suite_builder.group "Matrix with 3 channels" group_builder->
|
||||
zeros = Matrix.zeros 3 3 channels=3
|
||||
ones = Matrix.ones 3 3 channels=3
|
||||
identity = Matrix.identity 3 3 channels=3
|
||||
twos = Matrix.from_vector (ones.to_vector . map (_*2)) . reshape rows=3 channels=3
|
||||
|
||||
Test.specify "should create from a vector" <|
|
||||
group_builder.specify "should create from a vector" <|
|
||||
Matrix.from_vector zeros.to_vector rows=3 channels=3 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector rows=3 channels=3 . should_equal ones
|
||||
|
||||
Test.specify "should be able to reshape" <|
|
||||
group_builder.specify "should be able to reshape" <|
|
||||
Matrix.from_vector zeros.to_vector . reshape rows=3 channels=3 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector . reshape rows=3 channels=3 . should_equal ones
|
||||
|
||||
Test.specify "should be able to convert to a vector" <|
|
||||
group_builder.specify "should be able to convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9 [0, 0, 0] . flat_map x->x)
|
||||
ones.to_vector . should_equal (Vector.fill 9 [1, 0, 0] . flat_map x->x)
|
||||
identity.to_vector . should_equal ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map (x -> [x, 0, 0]))
|
||||
|
||||
Test.specify "should allow normalizing values" <|
|
||||
group_builder.specify "should allow normalizing values" <|
|
||||
zeros.normalize . should_equal zeros
|
||||
ones.normalize . should_equal ones
|
||||
identity.normalize . should_equal identity
|
||||
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0]
|
||||
@ -250,101 +250,101 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*3 1) rows=3 channels=3)
|
||||
ones+1 . should_equal (Matrix.from_vector (ones.to_vector . map (+1)) rows=3 channels=3)
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Matrix.from_vector (Vector.fill 9*3 0.8) rows=3 channels=3)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
zeros+[1, 1, 1, 1] . should_equal (Matrix.from_vector (Vector.fill 9*3 1) rows=3 channels=3)
|
||||
ones+[1, 0] . should_equal twos
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
zeros+ones . should_equal ones
|
||||
ones+ones . should_equal twos
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=3)
|
||||
twos-1 . should_equal (Matrix.from_vector (twos.to_vector . map (_ - 1)) rows=3 channels=3)
|
||||
ones-0 . should_equal ones
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
ones-[1, 0] . should_equal zeros
|
||||
twos-[1, 0] . should_equal ones
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
ones-ones . should_equal zeros
|
||||
twos-ones . should_equal ones
|
||||
identity-zeros . should_equal identity
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal twos
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[2, 2] . should_equal twos
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
zeros*ones . should_equal zeros
|
||||
ones*twos . should_equal twos
|
||||
identity*zeros . should_equal zeros
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
twos/2 . should_equal ones
|
||||
ones/5 . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=3)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2, 1, 1, 1] . should_equal zeros
|
||||
twos/[2, 2, 2, 2] . should_equal ones
|
||||
ones/[5, 5, 5, 5] . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=3)
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
all_ones = ones.to_vector . map (_ -> 1)
|
||||
all_twos = twos.to_vector . map (_ -> 2)
|
||||
zeros/all_ones . should_equal zeros
|
||||
twos/all_twos . should_equal ones
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.group "Matrix with 4 channels" <|
|
||||
suite_builder.group "Matrix with 4 channels" group_builder->
|
||||
zeros = Matrix.zeros 3 3 channels=4
|
||||
ones = Matrix.ones 3 3 channels=4
|
||||
identity = Matrix.identity 3 3 channels=4
|
||||
twos = Matrix.from_vector (ones.to_vector . map (_*2)) . reshape rows=3 channels=4
|
||||
|
||||
Test.specify "should create from a vector" <|
|
||||
group_builder.specify "should create from a vector" <|
|
||||
Matrix.from_vector zeros.to_vector rows=3 channels=4 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector rows=3 channels=4 . should_equal ones
|
||||
|
||||
Test.specify "should be able to reshape" <|
|
||||
group_builder.specify "should be able to reshape" <|
|
||||
Matrix.from_vector zeros.to_vector . reshape rows=3 channels=4 . should_equal zeros
|
||||
Matrix.from_vector ones.to_vector . reshape rows=3 channels=4 . should_equal ones
|
||||
|
||||
Test.specify "should be able to convert to a vector" <|
|
||||
group_builder.specify "should be able to convert to a vector" <|
|
||||
zeros.to_vector . should_equal (Vector.fill 9 [0, 0, 0, 0] . flat_map x->x)
|
||||
ones.to_vector . should_equal (Vector.fill 9 [1, 0, 0, 0] . flat_map x->x)
|
||||
identity.to_vector . should_equal ([1, 0, 0, 0, 1, 0, 0, 0, 1] . flat_map (x -> [x, 0, 0, 0]))
|
||||
|
||||
Test.specify "should allow normalizing values" <|
|
||||
group_builder.specify "should allow normalizing values" <|
|
||||
zeros.normalize . should_equal zeros
|
||||
ones.normalize . should_equal ones
|
||||
identity.normalize . should_equal identity
|
||||
|
||||
Test.specify "should allow getting the value at a specified location" <|
|
||||
group_builder.specify "should allow getting the value at a specified location" <|
|
||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||
@ -353,74 +353,78 @@ spec =
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
group_builder.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*4 1) rows=3 channels=4)
|
||||
ones+1 . should_equal (Matrix.from_vector (ones.to_vector . map (+1)) rows=3 channels=4)
|
||||
identity+0 . should_equal identity
|
||||
zeros+0.8 . should_equal (Matrix.from_vector (Vector.fill 9*4 0.8) rows=3 channels=4)
|
||||
Test.specify "should be able to add a vector" <|
|
||||
group_builder.specify "should be able to add a vector" <|
|
||||
zeros+[1] . should_equal ones
|
||||
zeros+[1, 1, 1, 1] . should_equal (Matrix.from_vector (Vector.fill 9*4 1) rows=3 channels=4)
|
||||
ones+[1, 0] . should_equal twos
|
||||
identity+[0, 0] . should_equal identity
|
||||
identity+[] . should_equal identity
|
||||
Test.specify "should be able to add a matrix" <|
|
||||
group_builder.specify "should be able to add a matrix" <|
|
||||
zeros+ones . should_equal ones
|
||||
ones+ones . should_equal twos
|
||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to subtract a scalar" <|
|
||||
group_builder.specify "should be able to subtract a scalar" <|
|
||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=4)
|
||||
twos-1 . should_equal (Matrix.from_vector (twos.to_vector . map (_ - 1)) rows=3 channels=4)
|
||||
ones-0 . should_equal ones
|
||||
Test.specify "should be able to subtract a vector" <|
|
||||
group_builder.specify "should be able to subtract a vector" <|
|
||||
ones-[1, 0] . should_equal zeros
|
||||
twos-[1, 0] . should_equal ones
|
||||
identity-[0, 0] . should_equal identity
|
||||
identity-[] . should_equal identity
|
||||
Test.specify "should be able to subtract a matrix" <|
|
||||
group_builder.specify "should be able to subtract a matrix" <|
|
||||
ones-ones . should_equal zeros
|
||||
twos-ones . should_equal ones
|
||||
identity-zeros . should_equal identity
|
||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to multiply by a scalar" <|
|
||||
group_builder.specify "should be able to multiply by a scalar" <|
|
||||
ones*2 . should_equal twos
|
||||
zeros*2 . should_equal zeros
|
||||
identity*0 . should_equal zeros
|
||||
identity*1 . should_equal identity
|
||||
Test.specify "should be able to multiply by a vector" <|
|
||||
group_builder.specify "should be able to multiply by a vector" <|
|
||||
zeros*[2] . should_equal zeros
|
||||
ones*[2, 2] . should_equal twos
|
||||
identity*[0, 0] . should_equal zeros
|
||||
identity*[] . should_equal zeros
|
||||
Test.specify "should be able to multiply by a matrix" <|
|
||||
group_builder.specify "should be able to multiply by a matrix" <|
|
||||
zeros*ones . should_equal zeros
|
||||
ones*twos . should_equal twos
|
||||
identity*zeros . should_equal zeros
|
||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
Test.specify "should be able to divide by a scalar" <|
|
||||
group_builder.specify "should be able to divide by a scalar" <|
|
||||
zeros/2 . should_equal zeros
|
||||
twos/2 . should_equal ones
|
||||
ones/5 . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=4)
|
||||
Test.specify "should be able to divide by a vector" <|
|
||||
group_builder.specify "should be able to divide by a vector" <|
|
||||
zeros/[2, 1, 1, 1] . should_equal zeros
|
||||
twos/[2, 2, 2, 2] . should_equal ones
|
||||
ones/[5, 5, 5, 5] . should_equal (Matrix.from_vector (ones.to_vector . map (_ / 5)) rows=3 channels=4)
|
||||
Test.specify "should be able to divide by a matrix" <|
|
||||
group_builder.specify "should be able to divide by a matrix" <|
|
||||
all_ones = ones.to_vector . map (_ -> 1)
|
||||
all_twos = twos.to_vector . map (_ -> 2)
|
||||
zeros/all_ones . should_equal zeros
|
||||
twos/all_twos . should_equal ones
|
||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
group_builder.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||
o = Matrix.ones 2 3
|
||||
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -6,8 +6,8 @@ import Standard.Base.Runtime.Context
|
||||
from Standard.Image import Image, Read_Flag, Write_Flag
|
||||
import Standard.Image.Image_File_Format.Image_File_Format
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
polyglot java import java.lang.System as Java_System
|
||||
|
||||
@ -15,7 +15,7 @@ fetch addr file =
|
||||
if file.exists then Exit_Code.Success else
|
||||
Process.run "curl" [addr, "--silent", "--output", file.path] . exit_code
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
rgba_addr = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Hue_alpha_falloff.png/320px-Hue_alpha_falloff.png"
|
||||
rgba_file = enso_project.root / "rgba.png"
|
||||
pending = case fetch rgba_addr rgba_file of
|
||||
@ -24,63 +24,63 @@ spec =
|
||||
Exit_Code.Success ->
|
||||
Nothing
|
||||
|
||||
Test.group "Image.read" pending=pending <|
|
||||
Test.specify "should return error when read failed" <|
|
||||
suite_builder.group "Image.read" pending=pending group_builder->
|
||||
group_builder.specify "should return error when read failed" <|
|
||||
result = Image.read (enso_project.root / 'no_such_file.png')
|
||||
result . should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.IO_Error
|
||||
|
||||
Test.specify "should read a color image" <|
|
||||
group_builder.specify "should read a color image" <|
|
||||
img = Image.read rgba_file
|
||||
img.rows.should_equal 160
|
||||
img.columns.should_equal 320
|
||||
img.channels.should_equal 3
|
||||
|
||||
Test.specify "should read an image as grayscale" <|
|
||||
group_builder.specify "should read an image as grayscale" <|
|
||||
img = Image.read rgba_file Read_Flag.Grayscale
|
||||
img.rows.should_equal 160
|
||||
img.columns.should_equal 320
|
||||
img.channels.should_equal 1
|
||||
|
||||
Test.specify "should read an image with an alpha channel" <|
|
||||
group_builder.specify "should read an image with an alpha channel" <|
|
||||
img = Image.read rgba_file Read_Flag.Alpha_Channel
|
||||
img.rows.should_equal 160
|
||||
img.columns.should_equal 320
|
||||
img.channels.should_equal 4
|
||||
|
||||
Test.specify "should return error when write failed" <|
|
||||
group_builder.specify "should return error when write failed" <|
|
||||
out_file = enso_project.root / "no_such_directory" / "out.png"
|
||||
result = Image.read rgba_file . write out_file
|
||||
result.should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.IO_Error
|
||||
Test.specify "should write a PNG file with alpha channel" <|
|
||||
group_builder.specify "should write a PNG file with alpha channel" <|
|
||||
out_file = enso_project.root / "out_alpha.png"
|
||||
Image.read rgba_file Read_Flag.Alpha_Channel . write out_file
|
||||
Test.specify "should write a grayscale PNG file" <|
|
||||
group_builder.specify "should write a grayscale PNG file" <|
|
||||
out_file = enso_project.root / "out_gray.png"
|
||||
Image.read rgba_file Read_Flag.Grayscale . write out_file
|
||||
Test.specify "should write a PNG file with compression" <|
|
||||
group_builder.specify "should write a PNG file with compression" <|
|
||||
out_file = enso_project.root / "out.png"
|
||||
Image.read rgba_file . write out_file (Write_Flag.PNG_Compression 3) . should_equal Nothing
|
||||
Test.specify "should write a JPEG file with compression" <|
|
||||
group_builder.specify "should write a JPEG file with compression" <|
|
||||
out_file = enso_project.root / "out.jpeg"
|
||||
flags = [Write_Flag.JPEG_Quality 75, Write_Flag.JPEG_Optimize, Write_Flag.JPEG_Progressive]
|
||||
Image.read rgba_file . write out_file flags . should_equal Nothing
|
||||
|
||||
Test.group "Image File_Format" <|
|
||||
Test.specify "should recognise image files" <|
|
||||
suite_builder.group "Image File_Format" group_builder->
|
||||
group_builder.specify "should recognise image files" <|
|
||||
Auto_Detect.get_reading_format (enso_project.data / "data.jpg") . should_be_a Image_File_Format
|
||||
Auto_Detect.get_reading_format (enso_project.data / "data.png") . should_be_a Image_File_Format
|
||||
Auto_Detect.get_reading_format (enso_project.data / "data.bmp") . should_be_a Image_File_Format
|
||||
|
||||
Test.specify "should allow reading an Image" <|
|
||||
group_builder.specify "should allow reading an Image" <|
|
||||
img = Data.read rgba_file
|
||||
img.rows.should_equal 160
|
||||
img.columns.should_equal 320
|
||||
img.channels.should_equal 3
|
||||
|
||||
Test.group "Image Write" <|
|
||||
Test.specify "should write a Bitmap file" <|
|
||||
suite_builder.group "Image Write" group_builder->
|
||||
group_builder.specify "should write a Bitmap file" <|
|
||||
img = Image.read rgba_file
|
||||
|
||||
out = enso_project.root / "out_alpha.bmp"
|
||||
@ -93,7 +93,7 @@ spec =
|
||||
|
||||
out.delete_if_exists
|
||||
|
||||
Test.specify "should not write if Context.Output is disabled." <|
|
||||
group_builder.specify "should not write if Context.Output is disabled." <|
|
||||
img = Image.read rgba_file
|
||||
|
||||
out = enso_project.root / "out_alpha.bmp"
|
||||
@ -104,4 +104,8 @@ spec =
|
||||
|
||||
out.delete_if_exists
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.Image_Read_Write_Spec
|
||||
import project.Data.Image_Spec
|
||||
import project.Data.Matrix_Spec
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
Image_Read_Write_Spec.spec
|
||||
Matrix_Spec.spec
|
||||
Image_Spec.spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
Image_Read_Write_Spec.add_specs suite_builder
|
||||
Matrix_Spec.add_specs suite_builder
|
||||
Image_Spec.add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -19,6 +19,9 @@ export ENSO_META_TEST_ARGS=--run
|
||||
$ENSO_META_TEST_COMMAND --run test/Meta_Test_Suite_Tests
|
||||
```
|
||||
|
||||
Make sure to disable to colored output of the tests. That is, make sure that
|
||||
`ENSO_TEST_ANSI_COLORS` env var is not set.
|
||||
|
||||
## Creating the tests
|
||||
|
||||
The test runner browses the `data` directory for subdirectories. Each
|
||||
|
@ -1,8 +1,7 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Test import Test, Problems
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
catch_and_print ~action = Panic.catch Any action caught_panic->
|
||||
IO.println "Panic: "+caught_panic.payload.to_text
|
||||
|
@ -1,33 +1,37 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec = Test.group "Tests" <|
|
||||
Test.specify "some property" <|
|
||||
|
||||
add_specs suite_builder = suite_builder.group "Tests" group_builder->
|
||||
group_builder.specify "some property" <|
|
||||
xs = [2, 3, 4, 5]
|
||||
xs.each x->
|
||||
(x > 0).should_be_true
|
||||
|
||||
Test.specify "other property" <|
|
||||
group_builder.specify "other property" <|
|
||||
0.should_equal 0
|
||||
|
||||
Test.specify "pending property" pending="This test is supposed to be ignored." <|
|
||||
group_builder.specify "pending property" pending="This test is supposed to be ignored." <|
|
||||
0.should_equal 1
|
||||
|
||||
Test.specify "some failing property" <|
|
||||
group_builder.specify "some failing property" <|
|
||||
xs = [2, 3, 4, 5]
|
||||
xs.each x->
|
||||
x*x . should_equal 4
|
||||
|
||||
Test.specify "something OK" <|
|
||||
group_builder.specify "something OK" <|
|
||||
1 . should_equal 1
|
||||
|
||||
Test.specify "dataflow error" <|
|
||||
group_builder.specify "dataflow error" <|
|
||||
Error.throw (Illegal_Argument.Error "some error") . should_equal 0
|
||||
|
||||
Test.specify "panic" <|
|
||||
group_builder.specify "panic" <|
|
||||
Panic.throw (Illegal_Argument.Error "some error")
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
Tests: [3/6, ???ms]
|
||||
[FAILED] Tests: [3/6, ???ms]
|
||||
- some property [???ms]
|
||||
- other property [???ms]
|
||||
- [PENDING] pending property
|
||||
@ -8,16 +8,14 @@ Tests: [3/6, ???ms]
|
||||
- something OK [???ms]
|
||||
- [FAILED] dataflow error [???ms]
|
||||
Reason: An unexpected dataflow error ((Illegal_Argument.Error 'some error' Nothing)) has been matched (at ???/fail_report/Main.enso:28:9-74).
|
||||
at <enso> Error.throw(Internal)
|
||||
at <enso> Main.spec<arg-0>(???/fail_report/Main.enso:28:9-57)
|
||||
???
|
||||
at <enso> Main.main(???/fail_report/Main.enso:33:8-31)
|
||||
at <enso> Main.main(???/fail_report/Main.enso:36:5-25)
|
||||
- [FAILED] panic [???ms]
|
||||
Reason: An unexpected panic was thrown: (Illegal_Argument.Error 'some error' Nothing)
|
||||
at <enso> Panic.throw(Internal)
|
||||
at <enso> Main.spec<arg-1>(???/fail_report/Main.enso:31:9-57)
|
||||
???
|
||||
at <enso> Main.main(???/fail_report/Main.enso:33:8-31)
|
||||
at <enso> Main.main(???/fail_report/Main.enso:36:5-25)
|
||||
3 tests succeeded.
|
||||
3 tests failed.
|
||||
1 tests skipped.
|
||||
0 groups skipped.
|
||||
|
@ -1,10 +1,10 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec = Test.group "Tests" <|
|
||||
Test.specify "some property" <|
|
||||
|
||||
add_specs suite_builder = suite_builder.group "Tests" group_builder->
|
||||
group_builder.specify "some property" <|
|
||||
xs = [2, 3, 4, 5]
|
||||
xs.each x->
|
||||
Test.with_clue ("{x = "+x.to_text+", x > 0}: ") <|
|
||||
@ -12,4 +12,8 @@ spec = Test.group "Tests" <|
|
||||
Test.with_clue ("{x = "+x.to_text+", x*x == 4}: ") <|
|
||||
x*x . should_equal 4
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
Tests: [0/1, ???ms]
|
||||
[FAILED] Tests: [0/1, ???ms]
|
||||
- [FAILED] some property [???ms]
|
||||
Reason: {x = 3, x*x == 4}: 9 did not equal 4 (at ???:13:17-36).
|
||||
0 tests succeeded.
|
||||
1 tests failed.
|
||||
0 tests skipped.
|
||||
0 groups skipped.
|
||||
|
@ -1,10 +1,10 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec = Test.group "Tests" <|
|
||||
Test.specify "some property" <|
|
||||
|
||||
add_specs suite_builder = suite_builder.group "Tests" group_builder->
|
||||
group_builder.specify "some property" <|
|
||||
xs = [2, 3, 4, 5]
|
||||
xs.each x->
|
||||
Test.with_clue "HMM: " <|
|
||||
@ -12,4 +12,8 @@ spec = Test.group "Tests" <|
|
||||
Test.with_clue ("{"+x.to_text+"}: ") <|
|
||||
x*x . should_equal 4
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
Tests: [0/1, ???ms]
|
||||
[FAILED] Tests: [0/1, ???ms]
|
||||
- [FAILED] some property [???ms]
|
||||
Reason: HMM: PREFIX {3}: 9 did not equal 4 (at ???:13:25-44). SUFFIX [???]
|
||||
0 tests succeeded.
|
||||
1 tests failed.
|
||||
0 tests skipped.
|
||||
0 groups skipped.
|
||||
|
@ -1,7 +1,7 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
type Setup
|
||||
Config command args
|
||||
@ -21,7 +21,7 @@ check_match expected_output actual_output =
|
||||
normalize_lines text =
|
||||
text.lines.join '\n'
|
||||
|
||||
spec setup =
|
||||
add_specs suite_builder setup =
|
||||
run_test source_path =
|
||||
args = setup.args + [source_path.absolute.normalize.to_text]
|
||||
builder = Process.new_builder setup.command args
|
||||
@ -29,13 +29,13 @@ spec setup =
|
||||
|
||||
tests = enso_project.data.list . filter (f-> f.is_directory) . sort on=(.name)
|
||||
tests.each test_dir->
|
||||
Test.group test_dir.name <|
|
||||
suite_builder.group test_dir.name group_builder->
|
||||
description_path = test_dir / "test_description.txt"
|
||||
description = description_path.read_text.trim
|
||||
source_path = test_dir / "Main.enso"
|
||||
expected_output_path = test_dir / "stdout.txt"
|
||||
expected_output = expected_output_path.read_text
|
||||
Test.specify description <|
|
||||
group_builder.specify description <|
|
||||
result = run_test source_path
|
||||
if check_match (normalize_lines expected_output) (normalize_lines result.stdout) . not then
|
||||
message = 'The program output did not match the expected output, stored at ['+expected_output_path.to_text+'].'
|
||||
@ -47,10 +47,13 @@ main =
|
||||
setup = case Environment.get "ENSO_META_TEST_COMMAND" of
|
||||
Nothing ->
|
||||
IO.println "No test command specified, using the default setup relying on the `enso` launcher being available on system PATH. If you want to use a different setup specify the command with `ENSO_META_TEST_COMMAND` environment variable. If the run is supposed to take any arguments, they can be set by overriding the `ENSO_META_TEST_ARGS` environment variable. The arguments will be split on spaces. The path to the tested file will always be appended as a last argument."
|
||||
Setup.Config "enso" ["run"]
|
||||
Setup.Config "enso" ["--run"]
|
||||
command : Text ->
|
||||
args = case Environment.get "ENSO_META_TEST_ARGS" of
|
||||
Nothing -> []
|
||||
text : Text -> text.split " "
|
||||
Setup.Config command args
|
||||
Test_Suite.run_main (spec setup)
|
||||
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder setup
|
||||
suite.run_with_filter
|
||||
|
@ -1,25 +1,25 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
from Standard.Table import Table
|
||||
|
||||
sample_table = Table.new [["A", [1, 2, 3]]]
|
||||
sample_column = sample_table.get "A"
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
expect_type_representation value expected_text =
|
||||
type_name = Meta.get_qualified_type_name value . to_text
|
||||
type_name . should_equal <| expected_text
|
||||
simple_name = Meta.get_simple_type_name value . to_text
|
||||
type_name . ends_with simple_name . should_be_true
|
||||
|
||||
Test.group "Type Names of Visualization Defaults" <|
|
||||
suite_builder.group "Type Names of Visualization Defaults" group_builder->
|
||||
""" IMPORTANT: When updating this, also update the default values in
|
||||
app/gui/view/graph-editor/src/builtin/visualization/java_script/table.js:18 as this
|
||||
verifies that the type names do not go out of sync. Should be removed once
|
||||
https://github.com/enso-org/enso/issues/5195 is implemented.
|
||||
Test.specify "Type names should match table visualization expectations" <|
|
||||
group_builder.specify "Type names should match table visualization expectations" <|
|
||||
expect_type_representation [1,2] "Standard.Base.Data.Vector.Vector"
|
||||
expect_type_representation [1,2].to_array "Standard.Base.Data.Array.Array"
|
||||
expect_type_representation sample_table "Standard.Table.Data.Table.Table"
|
||||
|
@ -3,31 +3,31 @@ from Standard.Base import all
|
||||
from Standard.Table import Table
|
||||
import Standard.Visualization.Geo_Map
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
import project.Helpers
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
expect value expected_json_text =
|
||||
result = Geo_Map.process_to_json_text value
|
||||
Json.parse result . should_equal <| Json.parse expected_json_text
|
||||
|
||||
Test.group "Geo_Map" <|
|
||||
Test.specify "skips unrecognized columns" <|
|
||||
suite_builder.group "Geo_Map" group_builder->
|
||||
group_builder.specify "skips unrecognized columns" <|
|
||||
header = ['α' , 'β' , 'ω']
|
||||
row_1 = [11 , 10 , 09 ]
|
||||
row_2 = [21 , 20 , 19 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table '{}'
|
||||
|
||||
Test.specify "recognizes relevant columns" <|
|
||||
group_builder.specify "recognizes relevant columns" <|
|
||||
header = ['latitude' , 'longitude' , 'color' , 'label' , 'radius']
|
||||
row_1 = [11 , 10 , 'red' , 'name' , 195 ]
|
||||
table = Table.from_rows header [row_1]
|
||||
expect table '{"df_color":["red"],"df_label":["name"],"df_latitude":[11],"df_longitude":[10],"df_radius":[195]}'
|
||||
|
||||
Test.specify "is case-insensitive" <|
|
||||
group_builder.specify "is case-insensitive" <|
|
||||
header = ['latitude' , 'LONGITUDE' , 'LaBeL']
|
||||
row_1 = [11 , 10 , 09 ]
|
||||
row_2 = [21 , 20 , 19 ]
|
||||
|
@ -2,11 +2,11 @@ from Standard.Base import all
|
||||
|
||||
from Standard.Table import Column
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
import Standard.Test.Test_Result.Test_Result
|
||||
from Standard.Test_New import all
|
||||
import Standard.Test_New.Spec_Result.Spec_Result
|
||||
|
||||
Column.expect : Text -> Vector -> Test_Result
|
||||
Column.expect self name contents =
|
||||
|
||||
|
||||
Column.expect self name:Text contents:Vector -> Spec_Result =
|
||||
self.name.should_equal name
|
||||
self.to_vector.should_equal contents
|
||||
|
@ -4,8 +4,8 @@ from Standard.Table import Table
|
||||
|
||||
import Standard.Visualization.Helpers
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
from project.Helpers import all
|
||||
|
||||
@ -14,9 +14,9 @@ polyglot java import java.util.LinkedHashSet
|
||||
type My_Type
|
||||
Value foo
|
||||
|
||||
spec =
|
||||
Test.group "Table.lookup_ignore_case" <|
|
||||
Test.specify "ignores case and takes first matching" <|
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Table.lookup_ignore_case" group_builder->
|
||||
group_builder.specify "ignores case and takes first matching" <|
|
||||
header = ['A', 'a' , 'ω' , 'Ω']
|
||||
row_1 = [11 , 10 , 12 , 13]
|
||||
row_2 = [21 , 20 , 22 , 23]
|
||||
@ -28,9 +28,9 @@ spec =
|
||||
table.lookup_ignore_case 'b' . is_error . should_equal True
|
||||
table.lookup_ignore_case 'B' . is_error . should_equal True
|
||||
|
||||
Test.group "Table.rows" <|
|
||||
suite_builder.group "Table.rows" group_builder->
|
||||
table = Table.new [["X", [1, 2, 3, 4]], ["Y", [5, 6, 7, 8]], ["Z", ["A", "B", "C", "D"]]]
|
||||
Test.specify "should visualize nicely" <|
|
||||
group_builder.specify "should visualize nicely" <|
|
||||
Json.parse (table.rows . to_default_visualization_data) . should_equal <|
|
||||
Json.parse '[[1,5,"A"],[2,6,"B"],[3,7,"C"],[4,8,"D"]]'
|
||||
|
||||
@ -38,7 +38,7 @@ spec =
|
||||
t2 = Table.new [["X", 0.up_to 200 . to_vector]]
|
||||
t2.rows.to_default_visualization_data . should_equal (0.up_to 100 . map (x -> [x])).to_default_visualization_data
|
||||
|
||||
Test.group "Vector and Arrays" <|
|
||||
suite_builder.group "Vector and Arrays" group_builder->
|
||||
## Returns an array with the same contents as the given vector, surely backed by
|
||||
a Java array.
|
||||
make_java_array vector =
|
||||
@ -47,31 +47,31 @@ spec =
|
||||
builder.add x
|
||||
builder.toArray
|
||||
|
||||
Test.specify "should be able to be efficiently visualise a Vector" <|
|
||||
group_builder.specify "should be able to be efficiently visualise a Vector" <|
|
||||
vec = Vector.fill 1000 0
|
||||
text = vec.to_default_visualization_data
|
||||
json = Json.parse text
|
||||
json.should_equal <| Vector.fill 100 0
|
||||
|
||||
Test.specify "should be able to visualize an Enso Array" <|
|
||||
group_builder.specify "should be able to visualize an Enso Array" <|
|
||||
arr = Vector.fill 1000 0 . to_array
|
||||
text = arr.to_default_visualization_data
|
||||
json = Json.parse text
|
||||
json.should_equal <| Vector.fill 100 0
|
||||
|
||||
Test.specify "should be able to visualize a Polyglot Array" pending="`to_default_visualization_data` does not work for polyglot arrays" <|
|
||||
group_builder.specify "should be able to visualize a Polyglot Array" pending="`to_default_visualization_data` does not work for polyglot arrays" <|
|
||||
arr = make_java_array (Vector.fill 1000 0)
|
||||
text = arr.to_default_visualization_data
|
||||
json = Json.parse text
|
||||
json.should_equal <| Vector.fill 100 0
|
||||
|
||||
Test.group "Dataflow Error Visualization" <|
|
||||
Test.specify "should be able to be shown in the default visualization" <|
|
||||
suite_builder.group "Dataflow Error Visualization" group_builder->
|
||||
group_builder.specify "should be able to be shown in the default visualization" <|
|
||||
json = (Error.throw <| My_Type.Value "aaa").to_default_visualization_data
|
||||
Json.parse json . should_equal <|
|
||||
JS_Object.from_pairs [["type", "My_Type"], ["constructor", "Value"], ["foo", "aaa"]]
|
||||
|
||||
Test.specify "should be able to be shown in the default vector visualization" <|
|
||||
group_builder.specify "should be able to be shown in the default vector visualization" <|
|
||||
vec = [My_Type.Value "bar", Error.throw (My_Type.Value 42)]
|
||||
visualization_text = vec.to_default_visualization_data
|
||||
|
||||
@ -91,4 +91,8 @@ spec =
|
||||
]
|
||||
Json.parse expected_json
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -4,12 +4,12 @@ from Standard.Table import Table, Column
|
||||
|
||||
import Standard.Visualization.Histogram
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
import project
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
expect value expected_label expected_values =
|
||||
text = Histogram.process_to_json_text value
|
||||
json = Json.parse text
|
||||
@ -22,36 +22,36 @@ spec =
|
||||
JS_Object.from_pairs [['data', expected_data], expected_axis]
|
||||
json.should_equal expected_json
|
||||
|
||||
Test.group "Histogram Visualization" <|
|
||||
Test.specify "plots first column if none recognized" <|
|
||||
suite_builder.group "Histogram Visualization" group_builder->
|
||||
group_builder.specify "plots first column if none recognized" <|
|
||||
header = ['α', 'ω']
|
||||
row_1 = [11 , 10 ]
|
||||
row_2 = [21 , 20 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table 'α' [11,21]
|
||||
|
||||
Test.specify "plots 'value' numeric column if present" <|
|
||||
group_builder.specify "plots 'value' numeric column if present" <|
|
||||
header = ['α', 'value']
|
||||
row_1 = [11 , 10 ]
|
||||
row_2 = [21 , 20 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table 'value' [10,20]
|
||||
|
||||
Test.specify "is case-insensitive" <|
|
||||
group_builder.specify "is case-insensitive" <|
|
||||
header = ['α', 'Value']
|
||||
row_1 = [11 , 10 ]
|
||||
row_2 = [21 , 20 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table 'Value' [10,20]
|
||||
|
||||
Test.specify "plots column" <|
|
||||
group_builder.specify "plots column" <|
|
||||
column = Column.from_vector 'my_name' [1,4,6]
|
||||
expect column 'my_name' [1,4,6]
|
||||
|
||||
Test.specify "plots vector" <|
|
||||
group_builder.specify "plots vector" <|
|
||||
vector = [1,2,3]
|
||||
expect vector Nothing vector
|
||||
|
||||
Test.specify "plots range" <|
|
||||
group_builder.specify "plots range" <|
|
||||
vector = 2.up_to 5
|
||||
expect vector Nothing [2,3,4]
|
||||
|
@ -5,15 +5,14 @@ from Standard.Table import Table
|
||||
|
||||
import Standard.Visualization
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
type My_Type
|
||||
Value my_field
|
||||
|
||||
spec = Test.group "Serializable Visualization Identifiers" <|
|
||||
|
||||
Test.specify "serializes builtin visualizations in the correct format" <|
|
||||
add_specs suite_builder = suite_builder.group "Serializable Visualization Identifiers" group_builder->
|
||||
group_builder.specify "serializes builtin visualizations in the correct format" <|
|
||||
json_for_name n = JS_Object.from_pairs [["library", Nothing], ["name", n]] . to_text
|
||||
Visualization.Id.json.to_json . should_equal (json_for_name "JSON")
|
||||
Visualization.Id.scatter_plot.to_json . should_equal (json_for_name "Scatter Plot")
|
||||
@ -24,7 +23,7 @@ spec = Test.group "Serializable Visualization Identifiers" <|
|
||||
Visualization.Id.geo_map.to_json . should_equal (json_for_name "Geo Map")
|
||||
Visualization.Id.image.to_json . should_equal (json_for_name "Image")
|
||||
|
||||
Test.specify "serializes library visualizations in the correct format" <|
|
||||
group_builder.specify "serializes library visualizations in the correct format" <|
|
||||
expected p_name v_name =
|
||||
lib = JS_Object.from_pairs [["name", p_name]]
|
||||
JS_Object.from_pairs [["library", lib], ["name", v_name]] . to_text
|
||||
@ -33,17 +32,17 @@ spec = Test.group "Serializable Visualization Identifiers" <|
|
||||
v_1.to_json.should_equal (expected "enso_dev.Visualization_Tests" "My Vis")
|
||||
v_2.to_json.should_equal (expected "Standard.Base" "Other Vis")
|
||||
|
||||
Test.specify "specifies default JSON visualization for any type" <|
|
||||
group_builder.specify "specifies default JSON visualization for any type" <|
|
||||
My_Type.Value 30 . default_visualization . should_equal Visualization.Id.json
|
||||
"foobar".default_visualization.should_equal Visualization.Id.json
|
||||
True.default_visualization.should_equal Visualization.Id.json
|
||||
|
||||
Test.specify "specifies default Table visualization for Vector and Array type" <|
|
||||
group_builder.specify "specifies default Table visualization for Vector and Array type" <|
|
||||
[1,2,3].default_visualization.should_equal Visualization.Id.table
|
||||
[1,2,3].to_array.default_visualization.should_equal Visualization.Id.table
|
||||
|
||||
|
||||
Test.specify "should specify Table's default visualizations correctly" <|
|
||||
group_builder.specify "should specify Table's default visualizations correctly" <|
|
||||
c_1_1 = ['x', [1, 2, 3]]
|
||||
c_1_2 = ['Y', [5.3, 56.2, 6.3]]
|
||||
t_1 = Table.new [c_1_1, c_1_2]
|
||||
@ -60,4 +59,8 @@ spec = Test.group "Serializable Visualization Identifiers" <|
|
||||
t_3 = Table.new [c_3_1, c_3_2, c_3_3]
|
||||
t_3.default_visualization.should_equal Visualization.Id.table
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -6,8 +6,8 @@ import Standard.Examples
|
||||
import Standard.Visualization.Table as Table_Visualization
|
||||
import Standard.Visualization.Preprocessor as Preprocessor
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
t1 = """
|
||||
12
|
||||
23
|
||||
@ -26,11 +26,11 @@ long_table =
|
||||
col = ["col", 1.up_to 100 . to_vector]
|
||||
Table.new [col]
|
||||
|
||||
spec = Test.group "Lazy Table Visualization" <|
|
||||
Test.specify "Fold Map" <|
|
||||
add_specs suite_builder = suite_builder.group "Lazy Table Visualization" group_builder->
|
||||
group_builder.specify "Fold Map" <|
|
||||
(Table_Visualization.fold_map 0 (acc -> item -> [acc + item, acc + item]) [1,2,3]).should_equal [1,3,6]
|
||||
|
||||
Test.specify "Should return correct update" <|
|
||||
group_builder.specify "Should return correct update" <|
|
||||
update = Table_Visualization.compute_table_update sample_table [0,0] [0,0] [3,2] 5
|
||||
update.chunks.contains [[[0,0], [0,0]], "12345"] . should_be_true
|
||||
update.chunks.contains [[[0,0], [1,0]], "6789"] . should_be_true
|
||||
@ -39,7 +39,7 @@ spec = Test.group "Lazy Table Visualization" <|
|
||||
update.chunks.contains [[[1, 0], [0, 0]], "4"] . should_be_true
|
||||
update.chunks.contains [[[1, 1], [0, 0]], "5"] . should_be_true
|
||||
|
||||
Test.specify "Should return correct update" <|
|
||||
group_builder.specify "Should return correct update" <|
|
||||
update = Table_Visualization.compute_table_update sample_table [0,0] [1,0] [3,2] 5
|
||||
## update.should_equal []
|
||||
update.chunks.contains [[[0,0], [1,0]], "6789"] . should_be_true
|
||||
@ -50,14 +50,14 @@ spec = Test.group "Lazy Table Visualization" <|
|
||||
update.chunks.contains [[[2, 1], [0, 0]], "8"] . should_be_true
|
||||
|
||||
|
||||
Test.specify "Find end column helper should return correct column index" <|
|
||||
group_builder.specify "Find end column helper should return correct column index" <|
|
||||
(Table_Visualization.find_end_column sample_table 0 0 1).should_equal 0
|
||||
(Table_Visualization.find_end_column sample_table 0 2 1).should_equal 0
|
||||
(Table_Visualization.find_end_column sample_table 0 3 5).should_equal 2
|
||||
(Table_Visualization.find_end_column sample_table 1 4 5).should_equal 5
|
||||
(Table_Visualization.find_end_column sample_table 0 9999 5).should_equal 6
|
||||
|
||||
Test.specify "Find end row helper should return correct row index" <|
|
||||
group_builder.specify "Find end row helper should return correct row index" <|
|
||||
(Table_Visualization.find_end_row sample_table 1 4).should_equal 2
|
||||
(Table_Visualization.find_end_row sample_table 0 0).should_equal 0
|
||||
(Table_Visualization.find_end_row sample_table 1 0).should_equal 1
|
||||
@ -66,29 +66,29 @@ spec = Test.group "Lazy Table Visualization" <|
|
||||
(Table_Visualization.find_end_row long_table 50 10).should_equal 60
|
||||
|
||||
|
||||
Test.specify "Get column width helper should return correct colum width" <|
|
||||
group_builder.specify "Get column width helper should return correct colum width" <|
|
||||
(Table_Visualization.get_column_width (sample_table.columns.at 0)).should_equal 9
|
||||
(Table_Visualization.get_column_width (sample_table.columns.at 1)).should_equal 1
|
||||
(Table_Visualization.get_column_width (sample_table.columns.at 3)).should_equal 2
|
||||
|
||||
Test.specify "Get row height helper should return correct row height" <|
|
||||
group_builder.specify "Get row height helper should return correct row height" <|
|
||||
(Table_Visualization.get_row_height sample_table 0).should_equal 1
|
||||
|
||||
Test.specify "Get map_to_cumulative_sum helper should return correct result" <|
|
||||
group_builder.specify "Get map_to_cumulative_sum helper should return correct result" <|
|
||||
(Table_Visualization.map_to_cumulative_sum [1,2,3]).should_equal [1,3,6]
|
||||
(Table_Visualization.map_to_cumulative_sum [1,1,1,1,1,1]).should_equal [1,2,3,4,5,6]
|
||||
|
||||
Test.specify "Get find_first_over_cum_sum helper should return correct result" <|
|
||||
group_builder.specify "Get find_first_over_cum_sum helper should return correct result" <|
|
||||
(Table_Visualization.find_first_over_cum_sum [1,2,3] 2).should_equal 1
|
||||
(Table_Visualization.find_first_over_cum_sum [1,1,1,1,1,1,1,1] 4).should_equal 4
|
||||
|
||||
Test.specify "Get enumerate helper should return correct result" <|
|
||||
group_builder.specify "Get enumerate helper should return correct result" <|
|
||||
(Table_Visualization.enumerate ["A","B","C"]).should_equal [[0, "A"],[1,"B"],[2,"C"]]
|
||||
|
||||
Test.specify "get_chunks_for_row helper should return correct result" <|
|
||||
group_builder.specify "get_chunks_for_row helper should return correct result" <|
|
||||
(Table_Visualization.get_chunks_for_row sample_table 0 0 0 (1.up_to 4) 5 3).should_equal [[[1,0], "4"], [[2,0], "7"], [[3,0], "10"]]
|
||||
(Table_Visualization.get_chunks_for_row sample_table 0 0 0 (0.up_to 4) 5 3).should_equal [[[0, 0], "12345"], [[0,1], "6789"], [[1,0], "4"]]
|
||||
|
||||
Test.specify "compute_vertical_indices helper should return correct result" <|
|
||||
group_builder.specify "compute_vertical_indices helper should return correct result" <|
|
||||
(Table_Visualization.compute_vertical_indices sample_table 0 2 0 2).should_equal [[0, 0], [1, 0]]
|
||||
(Table_Visualization.compute_vertical_indices sample_table 0 2 1 2).should_equal [[1, 0], [2, 0]]
|
||||
|
@ -5,25 +5,25 @@ import Standard.Examples
|
||||
import Standard.Visualization.Text as TextVis
|
||||
import Standard.Visualization.Preprocessor as Preprocessor
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
sample_text_single_line = "ABCDEFGHIJKLMNOPQRS"
|
||||
sample_text_multi_line = """
|
||||
ABCDEFGHIJKLMNOPQRS
|
||||
1234567890
|
||||
|
||||
spec = Test.group "Lazy Text Visualization" <|
|
||||
Test.specify "Should provide the correct chunk data" <|
|
||||
add_specs suite_builder = suite_builder.group "Lazy Text Visualization" group_builder->
|
||||
group_builder.specify "Should provide the correct chunk data" <|
|
||||
(Preprocessor.lazy_preprocessor sample_text_multi_line [0,0] [1,1] 5).should_equal '{"chunks":[[[0,0],"ABCDE"]],"line_count":2,"longest_line":19}'
|
||||
(Preprocessor.lazy_preprocessor sample_text_multi_line [1,1] [1,1] 5).should_equal '{"chunks":[[[1,1],"67890"]],"line_count":2,"longest_line":10}'
|
||||
(Preprocessor.lazy_preprocessor sample_text_multi_line [0,0] [2,1] 5).should_equal '{"chunks":[[[0,0],"ABCDE"],[[1,0],"FGHIJ"]],"line_count":2,"longest_line":19}'
|
||||
(Preprocessor.lazy_preprocessor sample_text_multi_line [0,0] [1,2] 5).should_equal '{"chunks":[[[0,0],"ABCDE"],[[0,1],"12345"]],"line_count":2,"longest_line":19}'
|
||||
|
||||
Test.specify "Should provide a simple string for small data" <|
|
||||
group_builder.specify "Should provide a simple string for small data" <|
|
||||
(Preprocessor.lazy_preprocessor 10 [0,0] [1,1] 5).should_equal '10'
|
||||
(Preprocessor.lazy_preprocessor 'Just A Simple String' [0,0] [5,1] 15).should_equal '"Just A Simple String"'
|
||||
|
||||
Test.specify "Should provide null for out of bounds data" <|
|
||||
group_builder.specify "Should provide null for out of bounds data" <|
|
||||
(Preprocessor.lazy_preprocessor sample_text_multi_line [100,0] [1,1] 5).should_equal '{"chunks":[[[100,0],null]],"line_count":2,"longest_line":19}'
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.Default_Visualizations_Spec
|
||||
import project.Geo_Map_Spec
|
||||
@ -15,16 +15,19 @@ import project.Visualization_Spec
|
||||
import project.Widgets_Spec
|
||||
import project.Lazy_Table_Spec
|
||||
|
||||
main = Test_Suite.run_main <|
|
||||
Default_Visualizations_Spec.spec
|
||||
Geo_Map_Spec.spec
|
||||
Helpers_Spec.spec
|
||||
Histogram_Spec.spec
|
||||
Id_Spec.spec
|
||||
Lazy_Table_Spec.spec
|
||||
Lazy_Text_Spec.spec
|
||||
Scatter_Plot_Spec.spec
|
||||
SQL_Spec.spec
|
||||
Table_Spec.spec
|
||||
Visualization_Spec.spec
|
||||
Widgets_Spec.spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
Default_Visualizations_Spec.add_specs suite_builder
|
||||
Geo_Map_Spec.add_specs suite_builder
|
||||
Helpers_Spec.add_specs suite_builder
|
||||
Histogram_Spec.add_specs suite_builder
|
||||
Id_Spec.add_specs suite_builder
|
||||
Lazy_Table_Spec.add_specs suite_builder
|
||||
Lazy_Text_Spec.add_specs suite_builder
|
||||
Scatter_Plot_Spec.add_specs suite_builder
|
||||
SQL_Spec.add_specs suite_builder
|
||||
Table_Spec.add_specs suite_builder
|
||||
Visualization_Spec.add_specs suite_builder
|
||||
Widgets_Spec.add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -4,26 +4,42 @@ from Standard.Database import Database, SQLite, SQL_Query
|
||||
|
||||
import Standard.Visualization.SQL.Visualization
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
visualization_spec connection =
|
||||
connection.execute_update 'CREATE TABLE "T" ("A" VARCHAR, "B" INTEGER, "C" INTEGER)'
|
||||
t = connection.query (SQL_Query.Table_Name "T")
|
||||
Test.group "SQL Visualization" <|
|
||||
Test.specify "should provide type metadata for interpolations" <|
|
||||
q = t.filter ((t.at "B" == 2) && (t.at "A" == True)) Filter_Condition.Is_True . at "C"
|
||||
type Data
|
||||
Value ~data
|
||||
|
||||
connection self = self.data.at 0
|
||||
t self = self.data.at 1
|
||||
|
||||
setup = Data.Value <|
|
||||
enso_project.data.create_directory
|
||||
file = enso_project.data / "sqlite_test.db"
|
||||
file.delete_if_exists
|
||||
connection = Database.connect (SQLite file)
|
||||
connection.execute_update 'CREATE TABLE "T" ("A" VARCHAR, "B" INTEGER, "C" INTEGER)'
|
||||
t = connection.query (SQL_Query.Table_Name "T")
|
||||
[connection, t]
|
||||
|
||||
teardown self =
|
||||
self.connection.close
|
||||
file = enso_project.data / "sqlite_test.db"
|
||||
file.delete_if_exists
|
||||
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "SQL Visualization" group_builder->
|
||||
data = Data.setup
|
||||
|
||||
group_builder.teardown <|
|
||||
data.teardown
|
||||
|
||||
group_builder.specify "should provide type metadata for interpolations" <|
|
||||
q = data.t.filter ((data.t.at "B" == 2) && (data.t.at "A" == True)) Filter_Condition.Is_True . at "C"
|
||||
vis = Visualization.prepare_visualization q
|
||||
int_param = JS_Object.from_pairs [["value", 2], ["enso_type", "Standard.Base.Data.Numbers.Integer"]]
|
||||
str_param = JS_Object.from_pairs [["value", True], ["enso_type", "Standard.Base.Data.Boolean.Boolean"]]
|
||||
code = 'SELECT "T"."C" AS "C" FROM "T" AS "T" WHERE (("T"."B") = (?) AND ("T"."A") = (?))'
|
||||
json = JS_Object.from_pairs [["dialect", "SQLite"], ["code", code], ["interpolations", [int_param, str_param]]]
|
||||
vis . should_equal json.to_text
|
||||
spec =
|
||||
enso_project.data.create_directory
|
||||
file = enso_project.data / "sqlite_test.db"
|
||||
file.delete_if_exists
|
||||
connection = Database.connect (SQLite file)
|
||||
visualization_spec connection
|
||||
connection.close
|
||||
file.delete
|
||||
|
||||
|
@ -4,12 +4,12 @@ from Standard.Table import Table, Column
|
||||
|
||||
import Standard.Visualization.Scatter_Plot
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
import project
|
||||
|
||||
spec =
|
||||
add_specs suite_builder =
|
||||
expect_text text axis_expected_text data_expected_text =
|
||||
json = Json.parse text
|
||||
json.field_names.should_equal ['data', 'axis']
|
||||
@ -28,47 +28,47 @@ spec =
|
||||
labels x y = JS_Object.from_pairs [['x', axis x], ['y', axis y]] . to_text
|
||||
no_labels = 'null'
|
||||
|
||||
Test.group "Scatter Plot Visualization" <|
|
||||
Test.specify "plots first column if none recognized" <|
|
||||
suite_builder.group "Scatter Plot Visualization" group_builder->
|
||||
group_builder.specify "plots first column if none recognized" <|
|
||||
header = ['α', 'ω']
|
||||
row_1 = [11 , 10 ]
|
||||
row_2 = [21 , 20 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table (labels index 'α') '[{"x":0,"y":11},{"x":1,"y":21}]'
|
||||
|
||||
Test.specify "plots 'y' against indices when no 'x' recognized" <|
|
||||
group_builder.specify "plots 'y' against indices when no 'x' recognized" <|
|
||||
header = ['α', 'y']
|
||||
row_1 = [11 , 10 ]
|
||||
row_2 = [21 , 20 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table (labels index 'y') '[{"x":0,"y":10},{"x":1,"y":20}]'
|
||||
|
||||
Test.specify "recognizes all relevant columns" <|
|
||||
group_builder.specify "recognizes all relevant columns" <|
|
||||
header = ['x' , 'y' , 'size' , 'shape' , 'label' , 'color' ]
|
||||
row_1 = [11 , 10 , 50 , 'square' , 'label' , 'ff0000']
|
||||
table = Table.from_rows header [row_1]
|
||||
expect table (labels 'x' 'y') '[{"color":"ff0000","label":"label","shape":"square","size":50,"x":11,"y":10}]'
|
||||
|
||||
Test.specify "is case-insensitive" <|
|
||||
group_builder.specify "is case-insensitive" <|
|
||||
header = ['X' , 'Y' , 'Size' , 'Shape' , 'Label' , 'Color' ]
|
||||
row_1 = [11 , 10 , 50 , 'square' , 'label' , 'ff0000']
|
||||
table = Table.from_rows header [row_1]
|
||||
expect table (labels 'X' 'Y') '[{"color":"ff0000","label":"label","shape":"square","size":50,"x":11,"y":10}]'
|
||||
|
||||
Test.specify "uses first unrecognized numeric column as `y` fallback" <|
|
||||
group_builder.specify "uses first unrecognized numeric column as `y` fallback" <|
|
||||
header = ['x' , 'size' , 'name' , 'z' , 'ω']
|
||||
row_1 = [11 , 50 , 'circul' , 20 , 30]
|
||||
table = Table.from_rows header [row_1]
|
||||
expect table (labels 'x' 'z') '[{"size":50,"x":11,"y":20}]'
|
||||
|
||||
Test.specify "provided only recognized columns" <|
|
||||
group_builder.specify "provided only recognized columns" <|
|
||||
header = ['x', 'y' , 'bar' , 'size']
|
||||
row_1 = [11 , 10 , 'aa' , 40 ]
|
||||
row_2 = [21 , 20 , 'bb' , 50 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table (labels 'x' 'y') '[{"size":40,"x":11,"y":10},{"size":50,"x":21,"y":20}]'
|
||||
|
||||
Test.specify "provided only recognized columns within bounds" <|
|
||||
group_builder.specify "provided only recognized columns within bounds" <|
|
||||
header = ['x', 'y' , 'bar' , 'size']
|
||||
row_1 = [1 , 1 , '11' , 30 ]
|
||||
row_2 = [11 , 10 , 'aa' , 40 ]
|
||||
@ -79,18 +79,18 @@ spec =
|
||||
text = Scatter_Plot.process_to_json_text table bounds
|
||||
expect_text text (labels 'x' 'y') '[{"size":40,"x":11,"y":10},{"size":50,"x":21,"y":20}]'
|
||||
|
||||
Test.specify "used default index for `x` if none set" <|
|
||||
group_builder.specify "used default index for `x` if none set" <|
|
||||
header = [ 'y' , 'bar' , 'size']
|
||||
row_1 = [ 10 , 'aa' , 40 ]
|
||||
row_2 = [ 20 , 'bb' , 50 ]
|
||||
table = Table.from_rows header [row_1, row_2]
|
||||
expect table (labels index 'y') '[{"size":40,"x":0,"y":10},{"size":50,"x":1,"y":20}]'
|
||||
|
||||
Test.specify "using indices for x if given a vector" <|
|
||||
group_builder.specify "using indices for x if given a vector" <|
|
||||
vector = [0,10,20]
|
||||
expect vector no_labels '[{"x":0,"y":0},{"x":1,"y":10},{"x":2,"y":20}]'
|
||||
|
||||
Test.specify "limit the number of elements" <|
|
||||
group_builder.specify "limit the number of elements" <|
|
||||
vector = [0,10,20,30]
|
||||
text = Scatter_Plot.process_to_json_text vector limit=2
|
||||
json = Json.parse text
|
||||
@ -99,7 +99,7 @@ spec =
|
||||
data.should_be_a Vector
|
||||
data.length . should_equal 2
|
||||
|
||||
Test.specify "limit the number of squared elements" <|
|
||||
group_builder.specify "limit the number of squared elements" <|
|
||||
vector = (-15).up_to 15 . map (x -> x * x)
|
||||
text = Scatter_Plot.process_to_json_text vector limit=10
|
||||
json = Json.parse text
|
||||
@ -109,18 +109,22 @@ spec =
|
||||
data.length . should_equal 10
|
||||
(data.take (First 3) . sort on=(_.get "x")).to_text . should_equal '[{"x":0,"y":225}, {"x":15,"y":0}, {"x":29,"y":196}]'
|
||||
|
||||
Test.specify "filter the elements" <|
|
||||
group_builder.specify "filter the elements" <|
|
||||
vector = [0,10,20,30]
|
||||
bounds = [0,5,10,25]
|
||||
text = Scatter_Plot.process_to_json_text vector bounds
|
||||
expect_text text no_labels '[{"x":1,"y":10},{"x":2,"y":20}]'
|
||||
|
||||
Test.specify "using indices for x if given a column" <|
|
||||
group_builder.specify "using indices for x if given a column" <|
|
||||
column = Column.from_vector 'some_col' [10,2,3]
|
||||
expect column (labels 'index' 'some_col') '[{"x":0,"y":10},{"x":1,"y":2},{"x":2,"y":3}]'
|
||||
|
||||
Test.specify "using indices for x if given a range" <|
|
||||
group_builder.specify "using indices for x if given a range" <|
|
||||
value = 2.up_to 5
|
||||
expect value no_labels '[{"x":0,"y":2},{"x":1,"y":3},{"x":2,"y":4}]'
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -10,22 +10,34 @@ import Standard.Visualization.Table.Visualization
|
||||
import Standard.Visualization.Helpers
|
||||
import Standard.Visualization.Id.Id
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
|
||||
polyglot java import java.util.UUID
|
||||
|
||||
type Data
|
||||
Value ~data
|
||||
|
||||
t self = self.data.at 0
|
||||
t2 self = self.data.at 1
|
||||
|
||||
setup = Data.Value <|
|
||||
connection = Database.connect (SQLite In_Memory)
|
||||
in_mem = Table.new [["A", ['a', 'a', 'a']], ["B", [2, 2, 3]], ["C", [3, 5, 6]]]
|
||||
t = in_mem.select_into_database_table connection "T" primary_key=Nothing temporary=True
|
||||
t2 = Table.new [["A", [1, 2, 3]], ["B", [4, 5, 6]], ["C", [7, 8, 9]]]
|
||||
[t, t2]
|
||||
|
||||
|
||||
type Foo
|
||||
Value x
|
||||
|
||||
to_js_object : JS_Object
|
||||
to_js_object self = JS_Object.from_pairs [["x", self.x]]
|
||||
|
||||
visualization_spec connection =
|
||||
in_mem = Table.new [["A", ['a', 'a', 'a']], ["B", [2, 2, 3]], ["C", [3, 5, 6]]]
|
||||
t = in_mem.select_into_database_table connection "T" primary_key=Nothing temporary=True
|
||||
|
||||
add_specs suite_builder =
|
||||
make_json header data all_rows ixes_header ixes =
|
||||
p_header = ["header", header]
|
||||
p_data = ["data", data]
|
||||
@ -35,8 +47,10 @@ visualization_spec connection =
|
||||
pairs = [p_header, p_data, p_all_rows, p_ixes, p_ixes_header, ["type", "Table"]]
|
||||
JS_Object.from_pairs pairs . to_text
|
||||
|
||||
Test.group "Table Visualization" <|
|
||||
Test.specify "should forward internal errors" <|
|
||||
suite_builder.group "Table Visualization" group_builder->
|
||||
data = Data.setup
|
||||
|
||||
group_builder.specify "should forward internal errors" <|
|
||||
bad_table_test =
|
||||
bad_table = Database_Table.Value Nothing Nothing Nothing Nothing
|
||||
result = Panic.catch Any (Visualization.prepare_visualization bad_table 2) caught_panic->
|
||||
@ -45,33 +59,32 @@ visualization_spec connection =
|
||||
result.to_display_text . should_equal message
|
||||
Panic.catch Type_Error bad_table_test (x -> x.payload) . should_be_a Type_Error
|
||||
|
||||
Test.specify "should visualize database tables" <|
|
||||
vis = Visualization.prepare_visualization t 1
|
||||
group_builder.specify "should visualize database tables" <|
|
||||
vis = Visualization.prepare_visualization data.t 1
|
||||
json = make_json header=["A", "B", "C"] data=[['a'], [2], [3]] all_rows=3 ixes_header=[] ixes=[]
|
||||
vis . should_equal json
|
||||
|
||||
Test.specify "should visualize database columns" <|
|
||||
vis = Visualization.prepare_visualization (t.at "A") 2
|
||||
group_builder.specify "should visualize database columns" <|
|
||||
vis = Visualization.prepare_visualization (data.t.at "A") 2
|
||||
json = make_json header=["A"] data=[['a', 'a']] all_rows=3 ixes_header=[] ixes=[]
|
||||
vis . should_equal json
|
||||
|
||||
g = t.aggregate [Aggregate_Column.Group_By "A", Aggregate_Column.Group_By "B", Aggregate_Column.Average "C"] . at "Average C"
|
||||
g = data.t.aggregate [Aggregate_Column.Group_By "A", Aggregate_Column.Group_By "B", Aggregate_Column.Average "C"] . at "Average C"
|
||||
vis2 = Visualization.prepare_visualization g 1
|
||||
json2 = make_json header=["Average C"] data=[[4.0]] all_rows=2 ixes_header=[] ixes=[]
|
||||
vis2 . should_equal json2
|
||||
|
||||
t2 = Table.new [["A", [1, 2, 3]], ["B", [4, 5, 6]], ["C", [7, 8, 9]]]
|
||||
Test.specify "should visualize dataframe tables" <|
|
||||
vis = Visualization.prepare_visualization t2 1
|
||||
group_builder.specify "should visualize dataframe tables" <|
|
||||
vis = Visualization.prepare_visualization data.t2 1
|
||||
json = make_json header=["A", "B", "C"] data=[[1], [4], [7]] all_rows=3 ixes_header=["#"] ixes=[[0]]
|
||||
vis . should_equal json
|
||||
|
||||
Test.specify "should visualize dataframe columns" <|
|
||||
vis = Visualization.prepare_visualization (t2.at "A") 2
|
||||
group_builder.specify "should visualize dataframe columns" <|
|
||||
vis = Visualization.prepare_visualization (data.t2.at "A") 2
|
||||
json = make_json header=["A"] data=[[1, 2]] all_rows=3 ixes_header=["#"] ixes=[[0, 1]]
|
||||
vis . should_equal json
|
||||
|
||||
Test.specify "should handle Vectors" <|
|
||||
group_builder.specify "should handle Vectors" <|
|
||||
vis = Visualization.prepare_visualization [1, 2, 3] 2
|
||||
json = JS_Object.from_pairs [["type", "Vector"], ["all_rows_count", 3], ["json", [1, 2]]]
|
||||
vis . should_equal json.to_text
|
||||
@ -80,17 +93,17 @@ visualization_spec connection =
|
||||
json2 = JS_Object.from_pairs [["type", "Matrix"], ["all_rows_count", 2], ["json", [[1, 2], [3, 4]]], ["column_count", 2]]
|
||||
vis2 . should_equal json2.to_text
|
||||
|
||||
Test.specify "should handle Arrays" <|
|
||||
group_builder.specify "should handle Arrays" <|
|
||||
vis = Visualization.prepare_visualization ([1, 2, 3] . to_array) 2
|
||||
json = JS_Object.from_pairs [["type", "Vector"], ["all_rows_count", 3], ["json", [1, 2]]]
|
||||
vis . should_equal json.to_text
|
||||
|
||||
Test.specify "should handle other datatypes" <|
|
||||
group_builder.specify "should handle other datatypes" <|
|
||||
vis = Visualization.prepare_visualization (Foo.Value 42) 2
|
||||
json = JS_Object.from_pairs [["json", JS_Object.from_pairs [["_display_text_", (Foo.Value 42).to_display_text],["x", 42]]]]
|
||||
vis . should_equal json.to_text
|
||||
|
||||
Test.specify "should visualize value type info" <|
|
||||
group_builder.specify "should visualize value type info" <|
|
||||
make_json vt =
|
||||
js_object = vt.to_js_object
|
||||
pairs = [["_display_text_", vt.to_display_text]] + vt.to_js_object.field_names.map f-> [f, js_object.get f]
|
||||
@ -102,13 +115,8 @@ visualization_spec connection =
|
||||
Visualization.prepare_visualization Value_Type.Char . should_equal (make_json Value_Type.Char)
|
||||
Visualization.prepare_visualization Value_Type.Unsupported_Data_Type . should_equal (make_json Value_Type.Unsupported_Data_Type)
|
||||
|
||||
spec =
|
||||
enso_project.data.create_directory
|
||||
file = enso_project.data / "sqlite_test.db"
|
||||
file.delete_if_exists
|
||||
connection = Database.connect (SQLite file)
|
||||
visualization_spec connection
|
||||
connection.close
|
||||
file.delete
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -4,16 +4,16 @@ import Standard.Examples
|
||||
|
||||
import Standard.Visualization
|
||||
|
||||
from Standard.Test import Test
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
|
||||
import Standard.Visualization.File_Upload.File_Being_Uploaded
|
||||
|
||||
spec = Test.group "File uploads" <|
|
||||
Test.specify "should be able to be signalled as uploading" <|
|
||||
add_specs suite_builder = suite_builder.group "File uploads" group_builder->
|
||||
group_builder.specify "should be able to be signalled as uploading" <|
|
||||
Visualization.file_uploading "file" . should_fail_with File_Being_Uploaded
|
||||
|
||||
Test.specify "should work whether a textual or file path is provided" <|
|
||||
group_builder.specify "should work whether a textual or file path is provided" <|
|
||||
result_file = Visualization.file_uploading Examples.csv . catch
|
||||
result_file.file_path . should_equal Examples.csv_path
|
||||
|
||||
|
@ -10,47 +10,51 @@ from Standard.AWS import all
|
||||
|
||||
import Standard.Visualization.Widgets
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
|
||||
add_specs suite_builder =
|
||||
connection = Database.connect (SQLite In_Memory)
|
||||
connection.execute_update 'CREATE TABLE "mock_table" ("A" VARCHAR, "B C" INTEGER, "D ""E""" BOOLEAN, "F.G/H\\I" REAL)'
|
||||
connection.execute_update 'CREATE TABLE "another" ("A" VARCHAR, "B C" INTEGER, "D ""E""" BOOLEAN, "F.G/H\\I" REAL)'
|
||||
connection.execute_update 'CREATE TABLE "a_table" ("A" VARCHAR, "B C" INTEGER, "D ""E""" BOOLEAN, "F.G/H\\I" REAL)'
|
||||
|
||||
Test.group "Widgets for In-Database Connection with table types" <|
|
||||
Test.specify "works for `tables`" <|
|
||||
suite_builder.group "Widgets for In-Database Connection with table types" group_builder->
|
||||
group_builder.specify "works for `tables`" <|
|
||||
result = Widgets.get_widget_json connection .tables ["types"]
|
||||
result.should_contain "'TABLE'"
|
||||
result.should_contain "'VIEW'"
|
||||
|
||||
Test.group "Widgets for In-Database Connection with table name sets" <|
|
||||
Test.specify "works for `query` and `read`" <|
|
||||
suite_builder.group "Widgets for In-Database Connection with table name sets" group_builder->
|
||||
group_builder.specify "works for `query` and `read`" <|
|
||||
choices = ['a_table', 'another', 'mock_table'] . map n-> Choice.Option n n.pretty
|
||||
expect = [["query", Widget.Single_Choice choices Nothing Display.Always]] . to_json
|
||||
Widgets.get_widget_json connection .query ["query"] . should_equal expect
|
||||
Widgets.get_widget_json connection .read ["query"] . should_equal expect
|
||||
|
||||
Test.group "Widgets for In-Database Table with column name sets" <|
|
||||
suite_builder.group "Widgets for In-Database Table with column name sets" group_builder->
|
||||
mock_table = connection.query "mock_table"
|
||||
|
||||
Test.specify "works for `get` and `at`" <|
|
||||
group_builder.specify "works for `get` and `at`" <|
|
||||
choices = mock_table.column_names . map n-> Choice.Option n n.pretty
|
||||
expect = [["selector", Widget.Single_Choice choices Nothing Display.Always]] . to_json
|
||||
Widgets.get_widget_json mock_table .get ["selector"] . should_equal expect
|
||||
Widgets.get_widget_json mock_table .at ["selector"] . should_equal expect
|
||||
|
||||
Test.specify "works for `filter`" <|
|
||||
group_builder.specify "works for `filter`" <|
|
||||
choices = mock_table.column_names . map n-> Choice.Option n n.pretty
|
||||
expect = [["column", Widget.Single_Choice choices Nothing Display.Always]] . to_json
|
||||
Widgets.get_widget_json mock_table .filter ["column"] . should_equal expect
|
||||
|
||||
Test.group "Widgets for Database" <|
|
||||
Test.specify "works for `connect`" <|
|
||||
suite_builder.group "Widgets for Database" group_builder->
|
||||
group_builder.specify "works for `connect`" <|
|
||||
result = Widgets.get_widget_json Database .connect ["details"]
|
||||
result.should_contain "SQLite"
|
||||
result.should_contain "Postgres"
|
||||
result.should_contain "Redshift"
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -8,22 +8,26 @@ from Standard.Table import Table
|
||||
|
||||
import Standard.Visualization.Widgets
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
Test.group "Widgets for In-Memory with column name sets" <|
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Widgets for In-Memory with column name sets" group_builder->
|
||||
mock_table = Table.from_rows ["A", "B C", 'D "E"', "F.G/H\I"] []
|
||||
|
||||
Test.specify "works for `get` and `at`" <|
|
||||
group_builder.specify "works for `get` and `at`" <|
|
||||
choices = mock_table.column_names . map n-> Choice.Option n n.pretty
|
||||
expect = [["selector", Widget.Single_Choice choices Nothing Display.Always]] . to_json
|
||||
Widgets.get_widget_json mock_table .get ["selector"] . should_equal expect
|
||||
Widgets.get_widget_json mock_table .at ["selector"] . should_equal expect
|
||||
|
||||
Test.specify "works for `filter`" <|
|
||||
group_builder.specify "works for `filter`" <|
|
||||
choices = mock_table.column_names . map n-> Choice.Option n n.pretty
|
||||
expect = [["column", Widget.Single_Choice choices Nothing Display.Always]] . to_json
|
||||
Widgets.get_widget_json mock_table .filter ["column"] . should_equal expect
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -7,12 +7,12 @@ import Standard.Base.Metadata.Display
|
||||
|
||||
import Standard.Visualization.Widgets
|
||||
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Test_New import all
|
||||
|
||||
spec =
|
||||
Test.group "Widgets for the Text type" <|
|
||||
Test.specify "works for `take` and `drop`" <|
|
||||
|
||||
add_specs suite_builder =
|
||||
suite_builder.group "Widgets for the Text type" group_builder->
|
||||
group_builder.specify "works for `take` and `drop`" <|
|
||||
mock_text = "abc def"
|
||||
default_widget = Text_Sub_Range.default_widget
|
||||
expect = [["range", default_widget]] . to_json
|
||||
@ -32,4 +32,8 @@ spec =
|
||||
labels.should_contain "After"
|
||||
labels.should_contain "Before_Last"
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Test import Test_Suite
|
||||
from Standard.Test_New import all
|
||||
|
||||
import project.Widgets.Database_Widgets_Spec
|
||||
import project.Widgets.Table_Widgets_Spec
|
||||
import project.Widgets.Text_Widgets_Spec
|
||||
|
||||
spec =
|
||||
Table_Widgets_Spec.spec
|
||||
Database_Widgets_Spec.spec
|
||||
Text_Widgets_Spec.spec
|
||||
add_specs suite_builder =
|
||||
Table_Widgets_Spec.add_specs suite_builder
|
||||
Database_Widgets_Spec.add_specs suite_builder
|
||||
Text_Widgets_Spec.add_specs suite_builder
|
||||
|
||||
main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
Loading…
Reference in New Issue
Block a user