mirror of
https://github.com/enso-org/enso.git
synced 2024-11-10 12:48:25 +03:00
Tidy up the remaining ones except Base... (#3797)
- Removed `Dubious constructor export` from Examples, Geo, Google_Api, Image and Test. - Updated Google_Api project to meet newer code standards. - Restructured `Standard.Test`: - `Main.enso` now exports `Bench`, `Faker`, `Problems`, `Test`, `Test_Suite` - `Test.Suite` methods moved into a `Test_Suite` type. - Moved `Bench.measure` into `Bench` type. - Separated the reporting to a `Test_Reporter` module. - Moved `Faker` methods into `Faker` type. - Removed `Verbs` and `.should` method. - Added `should_start_with` and `should_contain` extensions to `Any`. - Restructured `Standard.Image`: - Merged Codecs methods into `Image`. - Export `Image`, `Read_Flag`, `Write_Flag` and `Matrix` as types from `Main.enso`. - Merged the internal methods into `Matrix` and `Image`. - Fixed `Day_Of_Week` to be exported as a type and sort the `from` method.
This commit is contained in:
parent
47148a2ff1
commit
701c644d0e
@ -2,10 +2,6 @@ from Standard.Base import all
|
|||||||
|
|
||||||
polyglot java import java.time.DayOfWeek
|
polyglot java import java.time.DayOfWeek
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Data.Time.Day_Of_Week.Day_Of_Week import all
|
|
||||||
from project.Data.Time.Day_Of_Week.Day_Of_Week export all
|
|
||||||
|
|
||||||
type Day_Of_Week
|
type Day_Of_Week
|
||||||
Sunday
|
Sunday
|
||||||
|
|
||||||
@ -27,17 +23,17 @@ type Day_Of_Week
|
|||||||
- `first_day`: The first day of the week.
|
- `first_day`: The first day of the week.
|
||||||
- `start_at_zero`: If True, first day of the week is 0 otherwise is 1.
|
- `start_at_zero`: If True, first day of the week is 0 otherwise is 1.
|
||||||
to_integer : Day_Of_Week -> Boolean -> Integer
|
to_integer : Day_Of_Week -> Boolean -> Integer
|
||||||
to_integer self first_day=Sunday start_at_zero=False =
|
to_integer self first_day=Day_Of_Week.Sunday start_at_zero=False =
|
||||||
day_number = case self of
|
day_number = case self of
|
||||||
Sunday -> 0
|
Day_Of_Week.Sunday -> 0
|
||||||
Monday -> 1
|
Day_Of_Week.Monday -> 1
|
||||||
Tuesday -> 2
|
Day_Of_Week.Tuesday -> 2
|
||||||
Wednesday -> 3
|
Day_Of_Week.Wednesday -> 3
|
||||||
Thursday -> 4
|
Day_Of_Week.Thursday -> 4
|
||||||
Friday -> 5
|
Day_Of_Week.Friday -> 5
|
||||||
Saturday -> 6
|
Day_Of_Week.Saturday -> 6
|
||||||
|
|
||||||
shifted = if first_day == Sunday then day_number else
|
shifted = if first_day == Day_Of_Week.Sunday then day_number else
|
||||||
(day_number + 7 - (first_day.to_integer start_at_zero=True)) % 7
|
(day_number + 7 - (first_day.to_integer start_at_zero=True)) % 7
|
||||||
|
|
||||||
shifted + if start_at_zero then 0 else 1
|
shifted + if start_at_zero then 0 else 1
|
||||||
@ -45,30 +41,10 @@ type Day_Of_Week
|
|||||||
## PRIVATE
|
## PRIVATE
|
||||||
to_java : DayOfWeek
|
to_java : DayOfWeek
|
||||||
to_java self = case self of
|
to_java self = case self of
|
||||||
Sunday -> DayOfWeek.SUNDAY
|
Day_Of_Week.Sunday -> DayOfWeek.SUNDAY
|
||||||
Monday -> DayOfWeek.MONDAY
|
Day_Of_Week.Monday -> DayOfWeek.MONDAY
|
||||||
Tuesday -> DayOfWeek.TUESDAY
|
Day_Of_Week.Tuesday -> DayOfWeek.TUESDAY
|
||||||
Wednesday -> DayOfWeek.WEDNESDAY
|
Day_Of_Week.Wednesday -> DayOfWeek.WEDNESDAY
|
||||||
Thursday -> DayOfWeek.THURSDAY
|
Day_Of_Week.Thursday -> DayOfWeek.THURSDAY
|
||||||
Friday -> DayOfWeek.FRIDAY
|
Day_Of_Week.Friday -> DayOfWeek.FRIDAY
|
||||||
Saturday -> DayOfWeek.SATURDAY
|
Day_Of_Week.Saturday -> DayOfWeek.SATURDAY
|
||||||
|
|
||||||
## Convert from an integer to a Day_Of_Week
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- `that`: The first day of the week.
|
|
||||||
- `first_day`: The first day of the week.
|
|
||||||
- `start_at_zero`: If True, first day of the week is 0 otherwise is 1.
|
|
||||||
from (that : Integer) (first_day:Day_Of_Week=Sunday) (start_at_zero:Boolean=False) =
|
|
||||||
shifted = if start_at_zero then that else that - 1
|
|
||||||
|
|
||||||
case (shifted < 0) || (shifted > 6) of
|
|
||||||
True ->
|
|
||||||
valid_range = if start_at_zero then "0-6" else "1-7"
|
|
||||||
message = "Invalid day of week (must be " + valid_range + ")."
|
|
||||||
Error.throw (Illegal_Argument_Error message)
|
|
||||||
False ->
|
|
||||||
day_number = if first_day == Sunday then shifted else
|
|
||||||
(shifted + (first_day.to_integer start_at_zero=True)) % 7
|
|
||||||
|
|
||||||
[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday].at day_number
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
import project.Data.Time.Day_Of_Week.Day_Of_Week
|
||||||
|
|
||||||
|
## Convert from an integer to a Day_Of_Week
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- `that`: The first day of the week.
|
||||||
|
- `first_day`: The first day of the week.
|
||||||
|
- `start_at_zero`: If True, first day of the week is 0 otherwise is 1.
|
||||||
|
Day_Of_Week.from (that : Integer) (first_day:Day_Of_Week=Day_Of_Week.Sunday) (start_at_zero:Boolean=False) =
|
||||||
|
shifted = if start_at_zero then that else that - 1
|
||||||
|
|
||||||
|
case (shifted < 0) || (shifted > 6) of
|
||||||
|
True ->
|
||||||
|
valid_range = if start_at_zero then "0-6" else "1-7"
|
||||||
|
message = "Invalid day of week (must be " + valid_range + ")."
|
||||||
|
Error.throw (Illegal_Argument_Error message)
|
||||||
|
False ->
|
||||||
|
day_number = if first_day == Day_Of_Week.Sunday then shifted else
|
||||||
|
(shifted + (first_day.to_integer start_at_zero=True)) % 7
|
||||||
|
|
||||||
|
[Day_Of_Week.Sunday, Day_Of_Week.Monday, Day_Of_Week.Tuesday, Day_Of_Week.Wednesday, Day_Of_Week.Thursday, Day_Of_Week.Friday, Day_Of_Week.Saturday].at day_number
|
@ -33,7 +33,8 @@ import project.Data.Time.Date
|
|||||||
import project.Data.Time.Date_Time
|
import project.Data.Time.Date_Time
|
||||||
import project.Data.Time.Time_Of_Day
|
import project.Data.Time.Time_Of_Day
|
||||||
import project.Data.Time.Time_Zone
|
import project.Data.Time.Time_Zone
|
||||||
import project.Data.Time.Day_Of_Week
|
import project.Data.Time.Day_Of_Week.Day_Of_Week
|
||||||
|
import project.Data.Time.Day_Of_Week_From
|
||||||
import project.Data.Vector
|
import project.Data.Vector
|
||||||
import project.Error.Common
|
import project.Error.Common
|
||||||
import project.Error.Problem_Behavior
|
import project.Error.Problem_Behavior
|
||||||
@ -77,7 +78,8 @@ export project.Data.Time.Date
|
|||||||
export project.Data.Time.Date_Time
|
export project.Data.Time.Date_Time
|
||||||
export project.Data.Time.Time_Of_Day
|
export project.Data.Time.Time_Of_Day
|
||||||
export project.Data.Time.Time_Zone
|
export project.Data.Time.Time_Zone
|
||||||
export project.Data.Time.Day_Of_Week
|
export project.Data.Time.Day_Of_Week.Day_Of_Week
|
||||||
|
export project.Data.Time.Day_Of_Week_From
|
||||||
export project.Data.Vector
|
export project.Data.Vector
|
||||||
export project.Error.Problem_Behavior
|
export project.Error.Problem_Behavior
|
||||||
export project.IO
|
export project.IO
|
||||||
|
@ -8,20 +8,14 @@ import Standard.Base.Data.Text.Regex.Engine.Default as Default_Engine
|
|||||||
|
|
||||||
from Standard.Table import Table, Column
|
from Standard.Table import Table, Column
|
||||||
|
|
||||||
import Standard.Image
|
from Standard.Image import Image, Read_Flag, Matrix
|
||||||
import Standard.Image.Codecs
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Main.Example_Error_Type import all
|
|
||||||
from project.Main.Example_Error_Type export all
|
|
||||||
|
|
||||||
## An example error type used in a number of examples.
|
## An example error type used in a number of examples.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- message: The message contained in the error type.
|
- message: The message contained in the error type.
|
||||||
type Example_Error_Type
|
type Example_Error_Type
|
||||||
Example_Error_Type_Data message
|
Error message
|
||||||
|
|
||||||
## The standard library data directory.
|
## The standard library data directory.
|
||||||
data_dir : File
|
data_dir : File
|
||||||
@ -126,21 +120,17 @@ type No_Methods
|
|||||||
no_such_method : No_Such_Method_Error
|
no_such_method : No_Such_Method_Error
|
||||||
no_such_method = Panic.recover Any No_Methods.frobnicate . catch
|
no_such_method = Panic.recover Any No_Methods.frobnicate . catch
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Main.My_Error import all
|
|
||||||
from project.Main.My_Error export all
|
|
||||||
|
|
||||||
## A simple error type for example purposes.
|
## A simple error type for example purposes.
|
||||||
type My_Error
|
type My_Error
|
||||||
My_Error_Data message
|
Error message
|
||||||
|
|
||||||
## Throws an error.
|
## Throws an error.
|
||||||
throw_error : Nothing ! My_Error
|
throw_error : Nothing ! My_Error
|
||||||
throw_error = Error.throw <| My_Error_Data "Example error."
|
throw_error = Error.throw <| My_Error.Error "Example error."
|
||||||
|
|
||||||
## Throws a panic.
|
## Throws a panic.
|
||||||
throw_panic : Nothing
|
throw_panic : Nothing
|
||||||
throw_panic = Panic.throw <| My_Error_Data "Example panic."
|
throw_panic = Panic.throw <| My_Error.Error "Example panic."
|
||||||
|
|
||||||
## A URL for open-source geographic data about the locations of bus-stop ads in
|
## A URL for open-source geographic data about the locations of bus-stop ads in
|
||||||
Los Angeles.
|
Los Angeles.
|
||||||
@ -193,11 +183,11 @@ image_file =
|
|||||||
the internet if it is not already present on your disk. If you do not want
|
the internet if it is not already present on your disk. If you do not want
|
||||||
this to happen, please place the image in the
|
this to happen, please place the image in the
|
||||||
`lib/Standard/Examples/<version>/data` folder for your Enso distribution.
|
`lib/Standard/Examples/<version>/data` folder for your Enso distribution.
|
||||||
image : Image.Image
|
image : Image
|
||||||
image = Image.read image_file [Codecs.Read_Alpha_Channel]
|
image = Image.read image_file [Read_Flag.Alpha_Channel]
|
||||||
|
|
||||||
## A matrix that corresponds to `image`.
|
## A matrix that corresponds to `image`.
|
||||||
matrix : Matrix.Matrix
|
matrix : Matrix
|
||||||
matrix = image.to_matrix
|
matrix = image.to_matrix
|
||||||
|
|
||||||
## A silly little function that adds one to the provided number.
|
## A silly little function that adds one to the provided number.
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Geo_Json.Object_Type import all
|
|
||||||
from project.Geo_Json.Object_Type export all
|
|
||||||
|
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
|
|
||||||
A type of GeoJSON object.
|
A type of GeoJSON object.
|
||||||
@ -24,8 +20,8 @@ type Object_Type
|
|||||||
Convert GeoJSON object type to Text.
|
Convert GeoJSON object type to Text.
|
||||||
to_text : Text
|
to_text : Text
|
||||||
to_text self = case self of
|
to_text self = case self of
|
||||||
Feature -> "Feature"
|
Object_Type.Feature -> "Feature"
|
||||||
Feature_Collection -> "FeatureCollection"
|
Object_Type.Feature_Collection -> "FeatureCollection"
|
||||||
|
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
|
|
||||||
|
@ -11,22 +11,22 @@ polyglot java import com.google.api.services.sheets.v4.Sheets
|
|||||||
## PRIVATE
|
## PRIVATE
|
||||||
type Google_Api_Client
|
type Google_Api_Client
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
type Google_Api_Client credential json_factory http_transport
|
Value credential json_factory http_transport
|
||||||
|
|
||||||
## Accesses a service responsible for working with Google Spreadsheets.
|
## Accesses a service responsible for working with Google Spreadsheets.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- app_name: the application name to use for making the API calls. This
|
- app_name: the application name to use for making the API calls. This
|
||||||
will show up in access logs etc.
|
will show up in access logs etc.
|
||||||
spreadsheets : Text -> Spreadsheets_Service
|
spreadsheets : Text -> Spreadsheets
|
||||||
spreadsheets self app_name='Enso' =
|
spreadsheets self app_name='Enso' =
|
||||||
service = Sheets.Builder.new self.http_transport self.json_factory self.credential . setApplicationName app_name . build
|
service = Sheets.Builder.new self.http_transport self.json_factory self.credential . setApplicationName app_name . build
|
||||||
Spreadsheets_Service service
|
Spreadsheets.Service service
|
||||||
|
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
type Spreadsheets_Service
|
type Spreadsheets
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
type Spreadsheets_Service java_service
|
Service java_service
|
||||||
|
|
||||||
## Gets a table with the given ID and sheet range.
|
## Gets a table with the given ID and sheet range.
|
||||||
|
|
||||||
@ -56,5 +56,5 @@ initialize secret_file =
|
|||||||
GoogleCredential.fromStream is . createScoped (Collections.singleton SheetsScopes.SPREADSHEETS)
|
GoogleCredential.fromStream is . createScoped (Collections.singleton SheetsScopes.SPREADSHEETS)
|
||||||
http_transport = GoogleNetHttpTransport.newTrustedTransport
|
http_transport = GoogleNetHttpTransport.newTrustedTransport
|
||||||
json_factory = GsonFactory.getDefaultInstance
|
json_factory = GsonFactory.getDefaultInstance
|
||||||
Google_Api_Client credential json_factory http_transport
|
Google_Api_Client.Value credential json_factory http_transport
|
||||||
|
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
from Standard.Base import all
|
|
||||||
|
|
||||||
import Standard.Image.Codecs.Internal
|
|
||||||
import Standard.Image.Data.Image
|
|
||||||
|
|
||||||
polyglot java import org.enso.image.Codecs as Java_Codecs
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Read an image from a file.
|
|
||||||
|
|
||||||
The functon reads images in RGB format, or RGBA if the
|
|
||||||
`Read_Alpha_Channel` flag is specified.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- location: the file to read.
|
|
||||||
- flags: the read flags.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Read the image.
|
|
||||||
Codecs.read "image.png"
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Read the image with alpha channel.
|
|
||||||
Codecs.read "image.png" Codecs.Read_Alpha_Channel
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Read the image and convert it to grayscale.
|
|
||||||
Codecs.read "image.png" Codecs.Read_Grayscale
|
|
||||||
read : (Text | File) -> (Read_Flag | Vector) -> Image ! File.IO_Error
|
|
||||||
read location flags=[] =
|
|
||||||
path = case location of
|
|
||||||
_ : File.File -> location.path
|
|
||||||
_ -> location
|
|
||||||
read_flags = case flags of
|
|
||||||
_ : Vector.Vector ->
|
|
||||||
if flags.is_empty then Java_Codecs.READ_FLAG_EMPTY else
|
|
||||||
flags.map .to_integer . reduce (_.bit_or _)
|
|
||||||
_ -> flags.to_integer
|
|
||||||
Panic.catch_java Any (Image.Image_Data (Java_Codecs.read path read_flags)) _->
|
|
||||||
Error.throw (File.IO_Error (File.new path) 'Failed to read the file')
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Write an image to a file.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- location: The location to write the image to.
|
|
||||||
- flags: A vector of flags that control how the image is written.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Write the image with applying png compression.
|
|
||||||
Codecs.write path image
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Write the image with applying png compression.
|
|
||||||
Codecs.write path image (Codecs.Write_Png_Compression 9)
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Write the image with applying several flags.
|
|
||||||
Codecs.write path image [Codecs.Write_Jpeg_Quality 40, Codecs.Write_Jpeg_Progressive]
|
|
||||||
Image.Image.write : (Text | File) -> (Write_Flag | Vector) -> Nothing ! File.IO_Error
|
|
||||||
Image.Image.write self location flags=[] =
|
|
||||||
path = case location of
|
|
||||||
_ : File.File -> location.path
|
|
||||||
_ -> location
|
|
||||||
write_flags = case flags of
|
|
||||||
_ : Vector.Vector -> flags
|
|
||||||
_ -> [flags]
|
|
||||||
int_flags = Internal.mat_of_int (write_flags.flat_map x-> [x.to_integer, x.value])
|
|
||||||
Panic.catch_java Any (Java_Codecs.write path self.opencv_mat int_flags) _->
|
|
||||||
Error.throw (File.IO_Error (File.new path) 'Failed to write to the file')
|
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Codecs.Read_Flag import all
|
|
||||||
from project.Codecs.Read_Flag export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
type Read_Flag
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Read the image with its alpha channel, otherwise the channel gets cropped.
|
|
||||||
Read_Alpha_Channel
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Always convert the image to a single channel grayscale image.
|
|
||||||
Read_Grayscale
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Use Geographic Data Abstraction Library (GDAL) driver to load images in
|
|
||||||
geospatial raster data formats.
|
|
||||||
Read_Gdal
|
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Codecs.Write_Flag import all
|
|
||||||
from project.Codecs.Write_Flag export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
type Write_Flag
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Sets the quality used when writing a JPEG.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- val: A quality value from 0 to 100 (the higher, the better).
|
|
||||||
Write_Jpeg_Quality val=95
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Enable progressive JPEG compression format. Disabled by default.
|
|
||||||
Write_Jpeg_Progressive
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Enable optimized JPEG encoding algorithms. Disabled by default.
|
|
||||||
Write_Jpeg_Optimize
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Sets the luma quality level used when writing a JPEG.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- val: A quality value from 0 to 100 (the higher, the better).
|
|
||||||
Write_Jpeg_Luma_Quality val=0
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Sets the chroma quality level used when writing a JPEG.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- val: A quality value from 0 to 100 (the higher, the better).
|
|
||||||
Write_Jpeg_Chroma_Quality val=0
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Sets the compression level used when writing a PNG.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- val: A compression level from 0 to 9. A higher value means a smaller
|
|
||||||
size but a longer compression time.
|
|
||||||
Write_Png_Compression val=3
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Sets the quality used when writing a WEBP image.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- val: A quality from 0 to 100 (the higher, the better). A quality
|
|
||||||
above 100 indicates that the encoder should use lossless compression.
|
|
||||||
Write_Webp_Quality val=101
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
value self = case self of
|
|
||||||
Write_Jpeg_Progressive -> 1
|
|
||||||
Write_Jpeg_Optimize -> 1
|
|
||||||
_ -> self.val
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
from Standard.Base import all
|
|
||||||
|
|
||||||
import Standard.Image.Codecs
|
|
||||||
|
|
||||||
polyglot java import org.opencv.core.MatOfInt
|
|
||||||
polyglot java import org.opencv.imgcodecs.Imgcodecs
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Codecs.Read_Flag.to_integer self = case self of
|
|
||||||
Codecs.Read_Alpha_Channel -> Imgcodecs.IMREAD_UNCHANGED
|
|
||||||
Codecs.Read_Grayscale -> Imgcodecs.IMREAD_GRAYSCALE
|
|
||||||
Codecs.Read_Gdal -> Imgcodecs.IMREAD_LOAD_GDAL
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Codecs.Write_Flag.to_integer self = case self of
|
|
||||||
Codecs.Write_Jpeg_Quality _ -> Imgcodecs.IMWRITE_JPEG_QUALITY
|
|
||||||
Codecs.Write_Jpeg_Progressive -> Imgcodecs.IMWRITE_JPEG_PROGRESSIVE
|
|
||||||
Codecs.Write_Jpeg_Optimize -> Imgcodecs.IMWRITE_JPEG_OPTIMIZE
|
|
||||||
Codecs.Write_Jpeg_Luma_Quality _ -> Imgcodecs.IMWRITE_JPEG_LUMA_QUALITY
|
|
||||||
Codecs.Write_Jpeg_Chroma_Quality _ -> Imgcodecs.IMWRITE_JPEG_CHROMA_QUALITY
|
|
||||||
Codecs.Write_Png_Compression _ -> Imgcodecs.IMWRITE_PNG_COMPRESSION
|
|
||||||
Codecs.Write_Webp_Quality _ -> Imgcodecs.IMWRITE_WEBP_QUALITY
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Create an OpenCV matrix.
|
|
||||||
mat_of_int : Vector Any -> MatOfInt
|
|
||||||
mat_of_int values = MatOfInt.new values.to_array
|
|
@ -1,14 +1,5 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Data.Image
|
|
||||||
|
|
||||||
polyglot java import org.enso.image.data.Histogram as Java_Histogram
|
|
||||||
|
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Data.Histogram.Histogram import all
|
|
||||||
from project.Data.Histogram.Histogram export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
type Histogram
|
type Histogram
|
||||||
|
|
||||||
@ -19,7 +10,7 @@ type Histogram
|
|||||||
Arguments:
|
Arguments:
|
||||||
- channel: The channel in the image for which this is a histogram.
|
- channel: The channel in the image for which this is a histogram.
|
||||||
- data: The histogram data.
|
- data: The histogram data.
|
||||||
Histogram_Data channel data
|
Value channel data
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -29,7 +20,6 @@ type Histogram
|
|||||||
Convert a histogram to JSON.
|
Convert a histogram to JSON.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Image
|
|
||||||
|
|
||||||
example_to_json =
|
example_to_json =
|
||||||
histo = Examples.image.histogram 0
|
histo = Examples.image.histogram 0
|
||||||
@ -38,22 +28,3 @@ type Histogram
|
|||||||
to_json self =
|
to_json self =
|
||||||
bins = Json.from_pairs [["bins", self.data]]
|
bins = Json.from_pairs [["bins", self.data]]
|
||||||
Json.from_pairs [["data", bins]]
|
Json.from_pairs [["data", bins]]
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Create a histogram for the specified channel of the image.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- channel: the channel number.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Create a histogram.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Image
|
|
||||||
|
|
||||||
example_histogram = Examples.image.histogram 0
|
|
||||||
Image.Image.histogram : Integer -> Histogram
|
|
||||||
Image.Image.histogram self channel =
|
|
||||||
hist = Java_Histogram.calculate self.opencv_mat channel
|
|
||||||
Histogram_Data channel (Vector.from_polyglot_array hist.get_data)
|
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Data.Image.Internal
|
import project.Data.Histogram.Histogram
|
||||||
import Standard.Image.Data.Matrix
|
import project.Data.Matrix.Matrix
|
||||||
|
import project.Data.Matrix_Error.Matrix_Error
|
||||||
|
|
||||||
|
polyglot java import org.enso.image.data.Histogram as Java_Histogram
|
||||||
polyglot java import org.enso.image.data.Image as Java_Image
|
polyglot java import org.enso.image.data.Image as Java_Image
|
||||||
|
polyglot java import org.enso.image.Codecs as Java_Codecs
|
||||||
|
polyglot java import org.opencv.core.MatOfInt
|
||||||
|
polyglot java import org.opencv.core.Mat
|
||||||
|
polyglot java import org.opencv.core.Scalar
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
type Image
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
Create an image from the array of values.
|
Create an image from the array of values.
|
||||||
|
|
||||||
@ -20,20 +28,79 @@ polyglot java import org.enso.image.data.Image as Java_Image
|
|||||||
> Example
|
> Example
|
||||||
Create an image from the vector.
|
Create an image from the vector.
|
||||||
|
|
||||||
import Standard.Image
|
from Standard.Image import Image
|
||||||
|
|
||||||
example_from_vector =
|
example_from_vector =
|
||||||
Image.from_vector [0, 0, 0, 0, 0, 0] rows=2 channels=1
|
Image.from_vector [0, 0, 0, 0, 0, 0] rows=2 channels=1
|
||||||
from_vector : Vector -> Integer -> Integer -> Image
|
from_vector : Vector -> Integer -> Integer -> Image
|
||||||
from_vector values rows=1 channels=1 =
|
from_vector values rows=1 channels=1 =
|
||||||
Image_Data (Java_Image.from_vector values.to_array rows channels)
|
Image.Value (Java_Image.from_vector values.to_array rows channels)
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
## UNSTABLE
|
||||||
from project.Data.Image.Image import all
|
|
||||||
from project.Data.Image.Image export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
Read an image from a file.
|
||||||
type Image
|
|
||||||
|
The function reads images in RGB format, or RGBA if the
|
||||||
|
`Read_Flag.Alpha_Channel` flag is specified.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- location: the file to read.
|
||||||
|
- flags: the read flags.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Read the image.
|
||||||
|
Image.read "image.png"
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Read the image with alpha channel.
|
||||||
|
Image.read "image.png" Read_Flag.Alpha_Channel
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Read the image and convert it to grayscale.
|
||||||
|
Image.read "image.png" Read_Flag.Grayscale
|
||||||
|
read : (Text | File) -> (Read_Flag | Vector) -> Image ! File.IO_Error
|
||||||
|
read location flags=[] =
|
||||||
|
path = case location of
|
||||||
|
_ : File.File -> location.path
|
||||||
|
_ -> location
|
||||||
|
read_flags = case flags of
|
||||||
|
_ : Vector.Vector ->
|
||||||
|
if flags.is_empty then Java_Codecs.READ_FLAG_EMPTY else
|
||||||
|
flags.map .to_integer . reduce (_.bit_or _)
|
||||||
|
_ -> flags.to_integer
|
||||||
|
Panic.catch_java Any (Image.Value (Java_Codecs.read path read_flags)) _->
|
||||||
|
Error.throw (File.IO_Error (File.new path) 'Failed to read the file')
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Write an image to a file.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- location: The location to write the image to.
|
||||||
|
- flags: A vector of flags that control how the image is written.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Write the image with applying png compression.
|
||||||
|
image.write path image
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Write the image with applying png compression.
|
||||||
|
image.write path image (Write_Flag.PNG_Compression 9)
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Write the image with applying several flags.
|
||||||
|
image.write path image [Write_Flag.JPEG_Quality 40, Write_Flag.JPEG_Progressive]
|
||||||
|
write : (Text | File) -> (Write_Flag | Vector) -> Nothing ! File.IO_Error
|
||||||
|
write self location flags=[] =
|
||||||
|
path = case location of
|
||||||
|
_ : File.File -> location.path
|
||||||
|
_ -> location
|
||||||
|
write_flags = case flags of
|
||||||
|
_ : Vector.Vector -> flags
|
||||||
|
_ -> [flags]
|
||||||
|
int_flags = MatOfInt.new (write_flags.flat_map x-> [x.to_integer, x.value]).to_array
|
||||||
|
Panic.catch_java Any (Java_Codecs.write path self.opencv_mat int_flags) _->
|
||||||
|
Error.throw (File.IO_Error (File.new path) 'Failed to write to the file')
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -45,7 +112,7 @@ type Image
|
|||||||
The image is represented with a matrix of rows x columns. Each
|
The image is represented with a matrix of rows x columns. Each
|
||||||
pixel is represented with a vector of 1 to 4 values (channels).
|
pixel is represented with a vector of 1 to 4 values (channels).
|
||||||
Pixel values are normalized in a range [0.0 .. 1.0].
|
Pixel values are normalized in a range [0.0 .. 1.0].
|
||||||
Image_Data opencv_mat
|
Value opencv_mat
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -100,10 +167,10 @@ type Image
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_get = Examples.image.get 10 10
|
example_get = Examples.image.get 10 10
|
||||||
get : Integer -> Integer -> Vector ! Matrix.Index_Out_Of_Bounds_Error
|
get : Integer -> Integer -> Vector ! Matrix_Error
|
||||||
get self row column =
|
get self row column =
|
||||||
if (row < 0) || (row >= self.rows) then Error.throw (Matrix.Index_Out_Of_Bounds_Error self.rows self.columns row) else
|
if (row < 0) || (row >= self.rows) then Error.throw (Matrix_Error.Index_Out_Of_Bounds_Error self.rows self.columns row) else
|
||||||
if (column < 0) || (column >= self.columns) then Error.throw (Matrix.Index_Out_Of_Bounds_Error self.rows self.columns column) else
|
if (column < 0) || (column >= self.columns) then Error.throw (Matrix_Error.Index_Out_Of_Bounds_Error self.rows self.columns column) else
|
||||||
arr = Java_Image.get self.opencv_mat row column
|
arr = Java_Image.get self.opencv_mat row column
|
||||||
Vector.from_polyglot_array arr
|
Vector.from_polyglot_array arr
|
||||||
|
|
||||||
@ -150,13 +217,13 @@ type Image
|
|||||||
Add a matrix to the image.
|
Add a matrix to the image.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_plus =
|
example_plus =
|
||||||
image = Examples.image
|
image = Examples.image
|
||||||
image + (Matrix.zeros rows=image.rows columns=image.columns channels=image.channels)
|
image + (Matrix.zeros rows=image.rows columns=image.columns channels=image.channels)
|
||||||
+ : (Number | Vector | Matrix) -> Image ! Matrix.Dimensions_Not_Equal
|
+ : (Number | Vector | Matrix) -> Image ! Matrix_Error
|
||||||
+ self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Image.add _ _ _)) . catch Any Internal.core_op_handler
|
+ self value = Panic.recover Any (core_op self.opencv_mat value (Java_Image.add _ _ _)) . catch Any core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -201,13 +268,13 @@ type Image
|
|||||||
Subtract a matrix from the image.
|
Subtract a matrix from the image.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_minus =
|
example_minus =
|
||||||
image = Examples.image
|
image = Examples.image
|
||||||
image - (Matrix.zeros rows=image.rows columns=image.columns channels=image.channels)
|
image - (Matrix.zeros rows=image.rows columns=image.columns channels=image.channels)
|
||||||
- : (Number | Vector | Matrix) -> Image ! Matrix.Dimensions_Not_Equal
|
- : (Number | Vector | Matrix) -> Image ! Matrix_Error
|
||||||
- self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Image.subtract _ _ _)) . catch Any Internal.core_op_handler
|
- self value = Panic.recover Any (core_op self.opencv_mat value (Java_Image.subtract _ _ _)) . catch Any core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -252,13 +319,13 @@ type Image
|
|||||||
Multiply a matrix and the image.
|
Multiply a matrix and the image.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_mul =
|
example_mul =
|
||||||
image = Examples.image
|
image = Examples.image
|
||||||
image * (Matrix.ones rows=image.rows columns=image.columns channels=image.channels)
|
image * (Matrix.ones rows=image.rows columns=image.columns channels=image.channels)
|
||||||
* : (Number | Vector | Matrix) -> Image ! Matrix.Dimensions_Not_Equal
|
* : (Number | Vector | Matrix) -> Image ! Matrix_Error
|
||||||
* self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Image.multiply _ _ _)) . catch Any Internal.core_op_handler
|
* self value = Panic.recover Any (core_op self.opencv_mat value (Java_Image.multiply _ _ _)) . catch Any core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -303,13 +370,13 @@ type Image
|
|||||||
Divide an image by a matrix.
|
Divide an image by a matrix.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_div =
|
example_div =
|
||||||
image = Examples.image
|
image = Examples.image
|
||||||
image / (Matrix.ones rows=image.rows columns=image.columns channels=image.channels)
|
image / (Matrix.ones rows=image.rows columns=image.columns channels=image.channels)
|
||||||
/ : (Number | Vector | Matrix) -> Image ! Matrix.Dimensions_Not_Equal
|
/ : (Number | Vector | Matrix) -> Image ! Matrix_Error
|
||||||
/ self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Image.divide _ _ _)) . catch Any Internal.core_op_handler
|
/ self value = Panic.recover Any (core_op self.opencv_mat value (Java_Image.divide _ _ _)) . catch Any core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -378,3 +445,53 @@ type Image
|
|||||||
to_matrix : Matrix
|
to_matrix : Matrix
|
||||||
to_matrix self = Matrix.from_vector self.to_vector self.rows self.channels
|
to_matrix self = Matrix.from_vector self.to_vector self.rows self.channels
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Create a histogram for the specified channel of the image.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- channel: the channel number.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Create a histogram.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
|
||||||
|
example_histogram = Examples.image.histogram 0
|
||||||
|
histogram : Integer -> Histogram
|
||||||
|
histogram self channel =
|
||||||
|
hist = Java_Histogram.calculate self.opencv_mat channel
|
||||||
|
Histogram.Value channel (Vector.from_polyglot_array hist.get_data)
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Apply a core matrix operation.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- mat: The matrix to operate on.
|
||||||
|
- value: The value to apply to the matrix.
|
||||||
|
- function: The function with which to apply `value` to `mat`.
|
||||||
|
core_op : Mat -> Any -> (Mat -> Scalar -> Mat -> Nothing) -> Nothing
|
||||||
|
core_op mat value function =
|
||||||
|
result = Mat.new
|
||||||
|
scalar = case value of
|
||||||
|
_ : Vector.Vector ->
|
||||||
|
Scalar.new value.to_array
|
||||||
|
Matrix.Value m ->
|
||||||
|
if ((m.rows == mat.rows) && (m.cols == mat.cols) && (m.channels == mat.channels)) then m else Panic.throw Matrix_Error.Dimensions_Not_Equal
|
||||||
|
_ ->
|
||||||
|
Scalar.all value
|
||||||
|
function mat scalar result
|
||||||
|
Image.Value result
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Handles errors in `core_op`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- error: The value to throw as an error.
|
||||||
|
core_op_handler : Any
|
||||||
|
core_op_handler error =
|
||||||
|
case error of
|
||||||
|
Matrix_Error.Dimensions_Not_Equal -> Error.throw error
|
||||||
|
_ -> Panic.throw error
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
from Standard.Base import all
|
|
||||||
|
|
||||||
import Standard.Image.Data.Image
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
polyglot java import org.enso.image.data.Image as Java_Image
|
|
||||||
polyglot java import org.opencv.core.Mat
|
|
||||||
polyglot java import org.opencv.core.Scalar
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Apply a core matrix operation.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- mat: The matrix to operate on.
|
|
||||||
- value: The value to apply to the matrix.
|
|
||||||
- function: The function with which to apply `value` to `mat`.
|
|
||||||
core_op : Mat -> Any -> (Mat -> Scalar -> Mat -> Nothing) -> Nothing
|
|
||||||
core_op mat value function =
|
|
||||||
result = Mat.new
|
|
||||||
scalar = case value of
|
|
||||||
_ : Vector.Vector ->
|
|
||||||
Scalar.new value.to_array
|
|
||||||
Matrix.Matrix_Data m ->
|
|
||||||
if ((m.rows == mat.rows) && (m.cols == mat.cols) && (m.channels == mat.channels)) then m else Panic.throw Matrix.Dimensions_Not_Equal
|
|
||||||
_ ->
|
|
||||||
Scalar.all value
|
|
||||||
function mat scalar result
|
|
||||||
Image.Image_Data result
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Handles errors in `core_op`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- error: The value to throw as an error.
|
|
||||||
core_op_handler : Any
|
|
||||||
core_op_handler error =
|
|
||||||
case error of
|
|
||||||
Matrix.Dimensions_Not_Equal -> Error.throw error
|
|
||||||
_ -> Panic.throw error
|
|
||||||
|
|
@ -1,89 +1,12 @@
|
|||||||
from Standard.Base import all hiding Index_Out_Of_Bounds_Error
|
from Standard.Base import all
|
||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Data.Histogram
|
import project.Data.Image.Image
|
||||||
import Standard.Image.Data.Image
|
import project.Data.Matrix_Error.Matrix_Error
|
||||||
import Standard.Image.Data.Matrix.Internal
|
|
||||||
|
|
||||||
polyglot java import org.enso.image.data.Matrix as Java_Matrix
|
polyglot java import org.enso.image.data.Matrix as Java_Matrix
|
||||||
|
polyglot java import org.opencv.core.Mat
|
||||||
## UNSTABLE
|
polyglot java import org.opencv.core.Scalar
|
||||||
|
|
||||||
Create a matrix with all elements set to zero.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- rows: the number of rows in the resulting matrix.
|
|
||||||
- columns: the number of columns in the resulitng matrix.
|
|
||||||
- channels: the number of channels in the resulting matrix.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Create a matrix.
|
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
example_zeros = Matrix.zeros rows=2 columns=2
|
|
||||||
zeros : Integer -> Integer -> Integer -> Matrix
|
|
||||||
zeros rows columns channels=1 =
|
|
||||||
Matrix_Data (Java_Matrix.zeros rows columns channels)
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Create a matrix with all elements set to one.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- rows: the number of rows in the resulting matrix.
|
|
||||||
- columns: the number of columns in the resulitng matrix.
|
|
||||||
- channels: the number of channels in the resulting matrix.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Create a matrix.
|
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
example_ones = Matrix.zeros rows=2 columns=2 channels=3
|
|
||||||
ones : Integer -> Integer -> Integer -> Matrix
|
|
||||||
ones rows columns channels=1 =
|
|
||||||
Matrix_Data (Java_Matrix.ones rows columns channels)
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Create an identity matrix containing ones on a main diagonal.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- rows: the number of rows in the resulting matrix.
|
|
||||||
- columns: the number of columns in the resulitng matrix.
|
|
||||||
- channels: the number of channels in the resulting matrix.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Create a matrix.
|
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
example_identity = Matrix.identity rows=2 columns=2 channels=3
|
|
||||||
identity : Integer -> Integer -> Integer -> Matrix
|
|
||||||
identity rows columns channels=1 =
|
|
||||||
Matrix_Data (Java_Matrix.identity rows columns channels)
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Create a matrix from the provided vector.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- values: the vector of numbers.
|
|
||||||
- rows: the number of rows in the resulting matrix.
|
|
||||||
- channels: the number of channels in the resulting matrix.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Create a matrix.
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
example_from_vector = Matrix.from_vector [1, 1, 0, 0] rows=2
|
|
||||||
from_vector : Vector -> Integer -> Integer -> Matrix
|
|
||||||
from_vector values rows=1 channels=1 =
|
|
||||||
Matrix_Data (Java_Matrix.from_vector values.to_array channels rows)
|
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
|
||||||
from project.Data.Matrix.Matrix import all
|
|
||||||
from project.Data.Matrix.Matrix export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
type Matrix
|
type Matrix
|
||||||
@ -98,7 +21,82 @@ type Matrix
|
|||||||
Each value of the matrix is represented with an array of
|
Each value of the matrix is represented with an array of
|
||||||
channels. In contrast to an Image data type, Matrix values are
|
channels. In contrast to an Image data type, Matrix values are
|
||||||
not normalized.
|
not normalized.
|
||||||
Matrix_Data opencv_mat
|
Value opencv_mat
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Create a matrix with all elements set to zero.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- rows: the number of rows in the resulting matrix.
|
||||||
|
- columns: the number of columns in the resulting matrix.
|
||||||
|
- channels: the number of channels in the resulting matrix.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Create a matrix.
|
||||||
|
|
||||||
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
|
example_zeros = Matrix.zeros rows=2 columns=2
|
||||||
|
zeros : Integer -> Integer -> Integer -> Matrix
|
||||||
|
zeros rows columns channels=1 =
|
||||||
|
Matrix.Value (Java_Matrix.zeros rows columns channels)
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Create a matrix with all elements set to one.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- rows: the number of rows in the resulting matrix.
|
||||||
|
- columns: the number of columns in the resulting matrix.
|
||||||
|
- channels: the number of channels in the resulting matrix.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Create a matrix.
|
||||||
|
|
||||||
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
|
example_ones = Matrix.zeros rows=2 columns=2 channels=3
|
||||||
|
ones : Integer -> Integer -> Integer -> Matrix
|
||||||
|
ones rows columns channels=1 =
|
||||||
|
Matrix.Value (Java_Matrix.ones rows columns channels)
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Create an identity matrix containing ones on a main diagonal.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- rows: the number of rows in the resulting matrix.
|
||||||
|
- columns: the number of columns in the resulting matrix.
|
||||||
|
- channels: the number of channels in the resulting matrix.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Create a matrix.
|
||||||
|
|
||||||
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
|
example_identity = Matrix.identity rows=2 columns=2 channels=3
|
||||||
|
identity : Integer -> Integer -> Integer -> Matrix
|
||||||
|
identity rows columns channels=1 =
|
||||||
|
Matrix.Value (Java_Matrix.identity rows columns channels)
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Create a matrix from the provided vector.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- values: the vector of numbers.
|
||||||
|
- rows: the number of rows in the resulting matrix.
|
||||||
|
- channels: the number of channels in the resulting matrix.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Create a matrix.
|
||||||
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
|
example_from_vector = Matrix.from_vector [1, 1, 0, 0] rows=2
|
||||||
|
from_vector : Vector -> Integer -> Integer -> Matrix
|
||||||
|
from_vector values rows=1 channels=1 =
|
||||||
|
Matrix.Value (Java_Matrix.from_vector values.to_array channels rows)
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -151,10 +149,10 @@ type Matrix
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_get = Examples.matrix.get 0 0
|
example_get = Examples.matrix.get 0 0
|
||||||
get : Integer -> Integer -> Vector ! Index_Out_Of_Bounds_Error
|
get : Integer -> Integer -> Vector ! Matrix_Error
|
||||||
get self row column =
|
get self row column =
|
||||||
if (row < 0) || (row >= self.rows) then Error.throw (Index_Out_Of_Bounds_Error self.rows self.columns row) else
|
if (row < 0) || (row >= self.rows) then Error.throw (Matrix_Error.Index_Out_Of_Bounds_Error self.rows self.columns row) else
|
||||||
if (column < 0) || (column >= self.columns) then Error.throw (Index_Out_Of_Bounds_Error self.rows self.columns column) else
|
if (column < 0) || (column >= self.columns) then Error.throw (Matrix_Error.Index_Out_Of_Bounds_Error self.rows self.columns column) else
|
||||||
arr = Java_Matrix.get self.opencv_mat row column
|
arr = Java_Matrix.get self.opencv_mat row column
|
||||||
Vector.from_polyglot_array arr
|
Vector.from_polyglot_array arr
|
||||||
|
|
||||||
@ -169,14 +167,14 @@ type Matrix
|
|||||||
> Example
|
> Example
|
||||||
Reshape the matrix to a new shape of 3 rows and 1 column, with 1 channel.
|
Reshape the matrix to a new shape of 3 rows and 1 column, with 1 channel.
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_rewhsape = Matrix.from_vector [0, 0, 0] . reshape rows=3 channels=1
|
example_reshape = Matrix.from_vector [0, 0, 0] . reshape rows=3 channels=1
|
||||||
reshape : Integer -> Integer -> Matrix
|
reshape : Integer -> Integer -> Matrix
|
||||||
reshape self rows channels=Nothing =
|
reshape self rows channels=Nothing =
|
||||||
case channels of
|
case channels of
|
||||||
Nothing -> Matrix_Data (self.opencv_mat.reshape self.channels rows)
|
Nothing -> Matrix.Value (self.opencv_mat.reshape self.channels rows)
|
||||||
_ -> Matrix_Data (self.opencv_mat.reshape channels rows)
|
_ -> Matrix.Value (self.opencv_mat.reshape channels rows)
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -213,8 +211,8 @@ type Matrix
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_plus = Examples.matrix + Examples.matrix
|
example_plus = Examples.matrix + Examples.matrix
|
||||||
+ : (Number | Vector | Matrix) -> Matrix ! Dimensions_Not_Equal
|
+ : (Number | Vector | Matrix) -> Matrix ! Matrix_Error
|
||||||
+ self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Matrix.add _ _ _)) . catch Internal.core_op_handler
|
+ self value = Panic.recover Any (core_op self.opencv_mat value (Java_Matrix.add _ _ _)) . catch core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -252,8 +250,8 @@ type Matrix
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_minus = Examples.matrix - Examples.matrix
|
example_minus = Examples.matrix - Examples.matrix
|
||||||
- : (Number | Vector | Matrix) -> Matrix ! Dimensions_Not_Equal
|
- : (Number | Vector | Matrix) -> Matrix ! Matrix_Error
|
||||||
- self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Matrix.subtract _ _ _)) . catch Internal.core_op_handler
|
- self value = Panic.recover Any (core_op self.opencv_mat value (Java_Matrix.subtract _ _ _)) . catch core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -296,8 +294,8 @@ type Matrix
|
|||||||
> Example
|
> Example
|
||||||
Multiply two matrices.
|
Multiply two matrices.
|
||||||
m * m
|
m * m
|
||||||
* : (Number | Vector | Matrix) -> Matrix ! Dimensions_Not_Equal
|
* : (Number | Vector | Matrix) -> Matrix ! Matrix_Error
|
||||||
* self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Matrix.multiply _ _ _)) . catch Internal.core_op_handler
|
* self value = Panic.recover Any (core_op self.opencv_mat value (Java_Matrix.multiply _ _ _)) . catch core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -334,8 +332,8 @@ type Matrix
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_div = Examples.matrix / Examples.matrix
|
example_div = Examples.matrix / Examples.matrix
|
||||||
/ : (Number | Vector | Matrix) -> Matrix ! Dimensions_Not_Equal
|
/ : (Number | Vector | Matrix) -> Matrix ! Matrix_Error
|
||||||
/ self value = Panic.recover Any (Internal.core_op self.opencv_mat value (Java_Matrix.divide _ _ _)) . catch Internal.core_op_handler
|
/ self value = Panic.recover Any (core_op self.opencv_mat value (Java_Matrix.divide _ _ _)) . catch core_op_handler
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -370,26 +368,26 @@ type Matrix
|
|||||||
> Example
|
> Example
|
||||||
Normalize a matrix from vector.
|
Normalize a matrix from vector.
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_normalize = Matrix.from_vector [0, 1, 2, 3, 4] . normalize
|
example_normalize = Matrix.from_vector [0, 1, 2, 3, 4] . normalize
|
||||||
|
|
||||||
> Example
|
> Example
|
||||||
Normalize a matrix of ones.
|
Normalize a matrix of ones.
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_normalize = Matrix.ones 2 3 . normalize
|
example_normalize = Matrix.ones 2 3 . normalize
|
||||||
|
|
||||||
> Example
|
> Example
|
||||||
Normalize an identity matrix.
|
Normalize an identity matrix.
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
|
||||||
example_normalize = Matrix.identity 3 3 . normalize
|
example_normalize = Matrix.identity 3 3 . normalize
|
||||||
normalize : Number -> Number -> Matrix
|
normalize : Number -> Number -> Matrix
|
||||||
normalize self min_value=0.0 max_value=1.0 =
|
normalize self min_value=0.0 max_value=1.0 =
|
||||||
Matrix_Data (Java_Matrix.normalize self.opencv_mat min_value max_value)
|
Matrix.Value (Java_Matrix.normalize self.opencv_mat min_value max_value)
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
@ -401,12 +399,12 @@ type Matrix
|
|||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
example_to_image = Examples.matrix.to_image
|
example_to_image = Examples.matrix.to_image
|
||||||
to_image : Image.Image
|
to_image : Image
|
||||||
to_image self = Image.Image (Image.from_vector self.normalize.to_vector self.rows self.channels)
|
to_image self = Image (Image.from_vector self.normalize.to_vector self.rows self.channels)
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
|
|
||||||
Get the elemets of this matrix as a vector.
|
Get the elements of this matrix as a vector.
|
||||||
|
|
||||||
> Example
|
> Example
|
||||||
Convert a matrix to a vector.
|
Convert a matrix to a vector.
|
||||||
@ -432,36 +430,34 @@ type Matrix
|
|||||||
to_json : Json
|
to_json : Json
|
||||||
to_json self = Json.String self.opencv_mat.to_text
|
to_json self = Json.String self.opencv_mat.to_text
|
||||||
|
|
||||||
# TODO Dubious constructor export
|
## PRIVATE
|
||||||
from project.Data.Matrix.Matrix_Error import all
|
|
||||||
from project.Data.Matrix.Matrix_Error export all
|
|
||||||
|
|
||||||
## UNSTABLE
|
Apply a core matrix operation.
|
||||||
type Matrix_Error
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Indicates that a matrix has been accessed with an illegal index.
|
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- rows: The number of rows in the matrix.
|
- mat: The matrix to operate on.
|
||||||
- columns: The number of columns in the matrix.
|
- value: The value to apply to the matrix.
|
||||||
- index: The requested index in the matrix.
|
- function: The function with which to apply `value` to `mat`.
|
||||||
Index_Out_Of_Bounds_Error rows columns index
|
core_op : Mat -> Any -> (Mat -> Scalar -> Mat -> Nothing) -> Nothing
|
||||||
|
core_op mat value function =
|
||||||
|
result = Mat.new
|
||||||
|
scalar = case value of
|
||||||
|
_ : Vector.Vector ->
|
||||||
|
Scalar.new value.to_array
|
||||||
|
Matrix.Value m ->
|
||||||
|
if ((m.rows == mat.rows) && (m.cols == mat.cols) && (m.channels == mat.channels)) then m else Panic.throw Matrix_Error.Dimensions_Not_Equal
|
||||||
|
_ ->
|
||||||
|
Scalar.all value
|
||||||
|
function mat scalar result
|
||||||
|
Matrix.Value result
|
||||||
|
|
||||||
## UNSTABLE
|
## PRIVATE
|
||||||
|
|
||||||
An error indicating that an operation has failed due to a mismatch of
|
Handles errors in `core_op`.
|
||||||
matrix dimensions.
|
|
||||||
Dimensions_Not_Equal
|
|
||||||
|
|
||||||
## UNSTABLE
|
|
||||||
|
|
||||||
Pretty-prints a matrix error to be readable by the users.
|
|
||||||
to_display_text : Text
|
|
||||||
to_display_text self = case self of
|
|
||||||
Index_Out_Of_Bounds_Error rows columns index ->
|
|
||||||
'For a matrix with dimensions ' + rows.to_text + 'x' + columns.to_text + ', the index ' + index.to_text + ' is out of bounds.'
|
|
||||||
Dimensions_Not_Equal ->
|
|
||||||
'Dimensions are not equal.'
|
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- error: The value to throw as an error.
|
||||||
|
core_op_handler error =
|
||||||
|
case error of
|
||||||
|
Matrix_Error.Dimensions_Not_Equal -> Error.throw error
|
||||||
|
_ -> Panic.throw error
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
from Standard.Base import all
|
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
|
||||||
|
|
||||||
polyglot java import org.enso.image.data.Matrix as Java_Matrix
|
|
||||||
polyglot java import org.opencv.core.Mat
|
|
||||||
polyglot java import org.opencv.core.Scalar
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Apply a core matrix operation.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- mat: The matrix to operate on.
|
|
||||||
- value: The value to apply to the matrix.
|
|
||||||
- function: The function with which to apply `value` to `mat`.
|
|
||||||
core_op : Mat -> Any -> (Mat -> Scalar -> Mat -> Nothing) -> Nothing
|
|
||||||
core_op mat value function =
|
|
||||||
result = Mat.new
|
|
||||||
scalar = case value of
|
|
||||||
_ : Vector.Vector ->
|
|
||||||
Scalar.new value.to_array
|
|
||||||
Matrix.Matrix_Data m ->
|
|
||||||
if ((m.rows == mat.rows) && (m.cols == mat.cols) && (m.channels == mat.channels)) then m else Panic.throw Matrix.Dimensions_Not_Equal
|
|
||||||
_ ->
|
|
||||||
Scalar.all value
|
|
||||||
function mat scalar result
|
|
||||||
Matrix.Matrix_Data result
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Handles errors in `core_op`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- error: The value to throw as an error.
|
|
||||||
core_op_handler error =
|
|
||||||
case error of
|
|
||||||
Matrix.Dimensions_Not_Equal -> Error.throw error
|
|
||||||
_ -> Panic.throw error
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
type Matrix_Error
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Indicates that a matrix has been accessed with an illegal index.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- rows: The number of rows in the matrix.
|
||||||
|
- columns: The number of columns in the matrix.
|
||||||
|
- index: The requested index in the matrix.
|
||||||
|
Index_Out_Of_Bounds_Error rows columns index
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
An error indicating that an operation has failed due to a mismatch of
|
||||||
|
matrix dimensions.
|
||||||
|
Dimensions_Not_Equal
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Pretty-prints a matrix error to be readable by the users.
|
||||||
|
to_display_text : Text
|
||||||
|
to_display_text self = case self of
|
||||||
|
Matrix_Error.Index_Out_Of_Bounds_Error rows columns index ->
|
||||||
|
'For a matrix with dimensions ' + rows.to_text + 'x' + columns.to_text + ', the index ' + index.to_text + ' is out of bounds.'
|
||||||
|
Matrix_Error.Dimensions_Not_Equal ->
|
||||||
|
'Dimensions are not equal.'
|
@ -1,9 +1,11 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Codecs
|
import project.Read_Flag.Read_Flag
|
||||||
import Standard.Image.Data.Histogram
|
import project.Write_Flag.Write_Flag
|
||||||
import Standard.Image.Data.Image
|
import project.Data.Image.Image
|
||||||
|
import project.Data.Matrix.Matrix
|
||||||
|
|
||||||
from Standard.Image.Codecs export read, write
|
export project.Read_Flag.Read_Flag
|
||||||
from Standard.Image.Data.Histogram export all
|
export project.Write_Flag.Write_Flag
|
||||||
from Standard.Image.Data.Image export all
|
export project.Data.Image.Image
|
||||||
|
export project.Data.Matrix.Matrix
|
||||||
|
28
distribution/lib/Standard/Image/0.0.0-dev/src/Read_Flag.enso
Normal file
28
distribution/lib/Standard/Image/0.0.0-dev/src/Read_Flag.enso
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
polyglot java import org.opencv.imgcodecs.Imgcodecs
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
type Read_Flag
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Read the image with its alpha channel, otherwise the channel gets cropped.
|
||||||
|
Alpha_Channel
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Always convert the image to a single channel grayscale image.
|
||||||
|
Grayscale
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Use Geographic Data Abstraction Library (GDAL) driver to load images in
|
||||||
|
geospatial raster data formats.
|
||||||
|
GDAL
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
to_integer self = case self of
|
||||||
|
Read_Flag.Alpha_Channel -> Imgcodecs.IMREAD_UNCHANGED
|
||||||
|
Read_Flag.Grayscale -> Imgcodecs.IMREAD_GRAYSCALE
|
||||||
|
Read_Flag.GDAL -> Imgcodecs.IMREAD_LOAD_GDAL
|
@ -0,0 +1,73 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
polyglot java import org.opencv.imgcodecs.Imgcodecs
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
type Write_Flag
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Sets the quality used when writing a JPEG.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- val: A quality value from 0 to 100 (the higher, the better).
|
||||||
|
JPEG_Quality val:Integer=95
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Enable progressive JPEG compression format. Disabled by default.
|
||||||
|
JPEG_Progressive
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Enable optimized JPEG encoding algorithms. Disabled by default.
|
||||||
|
JPEG_Optimize
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Sets the luma quality level used when writing a JPEG.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- val: A quality value from 0 to 100 (the higher, the better).
|
||||||
|
JPEG_Luma_Quality val:Integer=0
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Sets the chroma quality level used when writing a JPEG.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- val: A quality value from 0 to 100 (the higher, the better).
|
||||||
|
JPEG_Chroma_Quality val=0
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Sets the compression level used when writing a PNG.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- val: A compression level from 0 to 9. A higher value means a smaller
|
||||||
|
size but a longer compression time.
|
||||||
|
PNG_Compression val:Integer=3
|
||||||
|
|
||||||
|
## UNSTABLE
|
||||||
|
|
||||||
|
Sets the quality used when writing a WEBP image.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- val: A quality from 0 to 100 (the higher, the better). A quality
|
||||||
|
above 100 indicates that the encoder should use lossless compression.
|
||||||
|
WEBP_Quality val=101
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
value self = case self of
|
||||||
|
Write_Flag.JPEG_Progressive -> 1
|
||||||
|
Write_Flag.JPEG_Optimize -> 1
|
||||||
|
_ -> self.val
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
to_integer self = case self of
|
||||||
|
Write_Flag.JPEG_Quality _ -> Imgcodecs.IMWRITE_JPEG_QUALITY
|
||||||
|
Write_Flag.JPEG_Progressive -> Imgcodecs.IMWRITE_JPEG_PROGRESSIVE
|
||||||
|
Write_Flag.JPEG_Optimize -> Imgcodecs.IMWRITE_JPEG_OPTIMIZE
|
||||||
|
Write_Flag.JPEG_Luma_Quality _ -> Imgcodecs.IMWRITE_JPEG_LUMA_QUALITY
|
||||||
|
Write_Flag.JPEG_Chroma_Quality _ -> Imgcodecs.IMWRITE_JPEG_CHROMA_QUALITY
|
||||||
|
Write_Flag.PNG_Compression _ -> Imgcodecs.IMWRITE_PNG_COMPRESSION
|
||||||
|
Write_Flag.WEBP_Quality _ -> Imgcodecs.IMWRITE_WEBP_QUALITY
|
@ -47,7 +47,7 @@ export project.Excel.Excel_Range.Excel_Range
|
|||||||
|
|
||||||
export project.Data.Data_Formatter.Data_Formatter
|
export project.Data.Data_Formatter.Data_Formatter
|
||||||
|
|
||||||
import Standard.Geo.Geo_Json
|
from Standard.Geo.Geo_Json import Object_Type
|
||||||
|
|
||||||
## ALIAS To Table
|
## ALIAS To Table
|
||||||
|
|
||||||
@ -87,14 +87,14 @@ Json.Json.to_table self fields=Nothing = case self of
|
|||||||
Json.Array items ->
|
Json.Array items ->
|
||||||
rows = items.map item-> case item of
|
rows = items.map item-> case item of
|
||||||
Json.Object fs ->
|
Json.Object fs ->
|
||||||
row = if item.get_type == Geo_Json.Feature.to_text then item.get_feature_row else fs
|
row = if item.get_type == Object_Type.Feature.to_text then item.get_feature_row else fs
|
||||||
fields.map n-> row.get n . unwrap . catch Any (_ -> Nothing)
|
fields.map n-> row.get n . unwrap . catch Any (_ -> Nothing)
|
||||||
_ -> Vector.fill fields.length Nothing
|
_ -> Vector.fill fields.length Nothing
|
||||||
cols = fields.map_with_index i-> n->
|
cols = fields.map_with_index i-> n->
|
||||||
[n, rows.map (_.at i)]
|
[n, rows.map (_.at i)]
|
||||||
Table.new cols
|
Table.new cols
|
||||||
Json.Object _ ->
|
Json.Object _ ->
|
||||||
if self.get_type != Geo_Json.Feature_Collection.to_text then Error.throw (Invalid_Format_Error.Invalid_Format_Error_Data self "not being a feature collection") else
|
if self.get_type != Object_Type.Feature_Collection.to_text then Error.throw (Invalid_Format_Error.Invalid_Format_Error_Data self "not being a feature collection") else
|
||||||
case self.get "features" of
|
case self.get "features" of
|
||||||
Json.Array items ->
|
Json.Array items ->
|
||||||
feature_rows = items.map .get_feature_row
|
feature_rows = items.map .get_feature_row
|
||||||
|
@ -2,7 +2,8 @@ from Standard.Base import all
|
|||||||
import Standard.Base.System
|
import Standard.Base.System
|
||||||
import Standard.Base.Runtime.Ref
|
import Standard.Base.Runtime.Ref
|
||||||
|
|
||||||
## Measure the amount of time it takes to execute a given computation.
|
type Bench
|
||||||
|
## Measure the amount of time it takes to execute a given computation.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- act: The action to perform.
|
- act: The action to perform.
|
||||||
@ -15,12 +16,12 @@ import Standard.Base.Runtime.Ref
|
|||||||
of iterations of 1.
|
of iterations of 1.
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
example_measure =
|
example_measure =
|
||||||
Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1
|
Bench.measure Examples.get_boolean "foo" iter_size=2 num_iters=1
|
||||||
measure : Any -> Text -> Integer -> Integer -> Nothing
|
measure : Any -> Text -> Integer -> Integer -> Nothing
|
||||||
measure = ~act -> label -> iter_size -> num_iters ->
|
measure = ~act -> label -> iter_size -> num_iters ->
|
||||||
result = Ref.new 0.0
|
result = Ref.new 0.0
|
||||||
single_call = _ ->
|
single_call = _ ->
|
||||||
x1 = System.nano_time
|
x1 = System.nano_time
|
||||||
@ -29,16 +30,15 @@ measure = ~act -> label -> iter_size -> num_iters ->
|
|||||||
x2 - x1
|
x2 - x1
|
||||||
iteration = it_num ->
|
iteration = it_num ->
|
||||||
act_it_num = num_iters - it_num
|
act_it_num = num_iters - it_num
|
||||||
res = iter_size.times single_call
|
res = times iter_size single_call
|
||||||
avg = avg_list res
|
avg = avg_list res
|
||||||
fmt = (avg / 1000000).format "%.2f"
|
fmt = (avg / 1000000).format "%.2f"
|
||||||
result.put (result.get + avg)
|
result.put (result.get + avg)
|
||||||
IO.println (label + "/iteration:" + act_it_num.to_text + ": " + fmt + "ms")
|
IO.println (label + "/iteration:" + act_it_num.to_text + ": " + fmt + "ms")
|
||||||
num_iters.times iteration
|
times num_iters iteration
|
||||||
fmt_avg = (result.get / (1000000*num_iters)).format "%.2f"
|
fmt_avg = (result.get / (1000000*num_iters)).format "%.2f"
|
||||||
IO.println (label + " average: " + fmt_avg + "ms")
|
IO.println (label + " average: " + fmt_avg + "ms")
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
## PRIVATE
|
||||||
|
|
||||||
Reverses the provided list.
|
Reverses the provided list.
|
||||||
@ -96,11 +96,10 @@ len_list list =
|
|||||||
Perform an action a number of times.
|
Perform an action a number of times.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- act: The action to perform `self` number of times.
|
- act: The action to perform `count` number of times.
|
||||||
Number.times : List Any
|
times : Integer-> List Any
|
||||||
Number.times self act =
|
times count act =
|
||||||
go = results -> number -> if number == 0 then results else
|
go = results -> number -> if number == 0 then results else
|
||||||
@Tail_Call go (Cons (act number) results) number-1
|
@Tail_Call go (Cons (act number) results) number-1
|
||||||
res = reverse_list (go Nil self)
|
res = reverse_list (go Nil count)
|
||||||
res
|
res
|
||||||
|
|
||||||
|
410
distribution/lib/Standard/Test/0.0.0-dev/src/Extensions.enso
Normal file
410
distribution/lib/Standard/Test/0.0.0-dev/src/Extensions.enso
Normal file
@ -0,0 +1,410 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
import project.Test_Result.Test_Result
|
||||||
|
from project.Test import Test
|
||||||
|
|
||||||
|
## Expect a function to fail with the provided dataflow error.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- matcher: The expected type of dataflow error contained in `self`.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a computation should return an error of a given type.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_fail_with =
|
||||||
|
Examples.throw_error . should_fail_with Examples.My_Error
|
||||||
|
Any.should_fail_with : Any -> Integer -> Test_Result
|
||||||
|
Any.should_fail_with self matcher frames_to_skip=0 =
|
||||||
|
loc = Meta.get_source_location 1+frames_to_skip
|
||||||
|
Test.fail ("Expected an error " + matcher.to_text + " but no error occurred, instead got: " + self.to_text + " (at " + loc + ").")
|
||||||
|
|
||||||
|
## Expect a function to fail with the provided dataflow error.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- matcher: The expected type of dataflow error contained in `self`.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a computation should return an error of a given type.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_fail_with =
|
||||||
|
Examples.throw_error . should_fail_with Examples.My_Error
|
||||||
|
Error.should_fail_with : Any -> Integer -> Test_Result
|
||||||
|
Error.should_fail_with self matcher frames_to_skip=0 =
|
||||||
|
caught = self.catch
|
||||||
|
if caught.is_a matcher then Nothing else
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
Test.fail ("Expected error "+matcher.to_text+", but error " + caught.to_text + " has been returned (at " + loc + ").")
|
||||||
|
|
||||||
|
## Asserts that `self` value is equal to the expected value.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The value to check `self` for equality with.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one value should equal another,
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = Examples.add_1_to 1 . should_equal 2
|
||||||
|
Any.should_equal : Any -> Integer -> Test_Result
|
||||||
|
Any.should_equal self that frames_to_skip=0 = case self == that of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " did not equal " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is equal to the expected type value.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The type to check `self` for equality with.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that some type is equal to another.,
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = Examples.some_tpe . should_equal_tpe Vector.Vector
|
||||||
|
Any.should_equal_type : Any -> Integer -> Test_Result
|
||||||
|
Any.should_equal_type self that frames_to_skip=0 = case (self.is_same_object_as that) of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " did not equal type " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is not equal to the expected value.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The value to check `self` for equality with.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one value should equal another,
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_not_equal = Examples.add_1_to 1 . should_not_equal 2
|
||||||
|
Any.should_not_equal : Any -> Integer -> Test_Result
|
||||||
|
Any.should_not_equal self that frames_to_skip=0 = case self != that of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " did equal " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is not equal to the expected type value.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The type to check `self` for equality with.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that some type is equal to another.,
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_not_equal = Examples.some_tpe . should_not_equal_tpe Vector.Vector
|
||||||
|
Any.should_not_equal_type : Any -> Integer -> Test_Result
|
||||||
|
Any.should_not_equal_type self that frames_to_skip=0 = case (self.is_same_object_as that . not) of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " did equal type " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is a Text value and starts with `that`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The value to check `self` starts with.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one value should start with another.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_start_with = "Hello World!" . should_start_with "Hello"
|
||||||
|
Any.should_start_with : Text -> Integer -> Test_Result
|
||||||
|
Any.should_start_with self that frames_to_skip=0 = case self of
|
||||||
|
_ : Text -> if self.starts_with that then Test_Result.Success else
|
||||||
|
loc = Meta.get_source_location 3+frames_to_skip
|
||||||
|
msg = self.to_text + " does not start with " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
_ ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " is not a `Text` value (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is a Text value and contains `that`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The value to check `self` contains.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one value should contain another.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_start_with = "Hello World!" . should_contain "World"
|
||||||
|
Any.should_contain : Text -> Integer -> Test_Result
|
||||||
|
Any.should_contain self that frames_to_skip=0 = case self of
|
||||||
|
_ : Text -> if self.contains that then Test_Result.Success else
|
||||||
|
loc = Meta.get_source_location 3+frames_to_skip
|
||||||
|
msg = self.to_text + " does not contain " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
_ ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " is not a `Text` value (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is equal to the expected value.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- _: The value to check `self` for equality with.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one value should equal another,
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = Examples.add_1_to 1 . should_equal 2
|
||||||
|
Error.should_equal : Any -> Test_Result
|
||||||
|
Error.should_equal self _ frames_to_skip=0 = Test.fail_match_on_unexpected_error self 1+frames_to_skip
|
||||||
|
|
||||||
|
## Asserts that `self` is within `epsilon` from `that`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The value to compare `self` for equality with.
|
||||||
|
- epsilon: The epislon for comparing two decimal numbers.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Compare two decimal values.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = 1.1 . should_equal 1.1
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Compare two decimal values with an epsilon (tolerance).
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal =
|
||||||
|
1.00000001 . should_equal 1.00000002 epsilon=0.0001
|
||||||
|
Number.should_equal : Decimal -> Decimal -> Integer -> Test_Result
|
||||||
|
Number.should_equal self that epsilon=0 frames_to_skip=0 =
|
||||||
|
matches = case that of
|
||||||
|
_ : Number -> self.equals that epsilon
|
||||||
|
_ -> False
|
||||||
|
case matches of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = self.to_text + " did not equal " + that.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value is not an error.
|
||||||
|
|
||||||
|
It returns the original value, so that it can be inspected further.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a given action did not result in errors or warnings.
|
||||||
|
|
||||||
|
"foobar".write (enso_project.data / "f.txt") . should_succeed
|
||||||
|
Any.should_succeed : Boolean -> Integer -> Any
|
||||||
|
Any.should_succeed self frames_to_skip=0 =
|
||||||
|
_ = frames_to_skip
|
||||||
|
self
|
||||||
|
|
||||||
|
## Asserts that `self` value is not an error.
|
||||||
|
|
||||||
|
It returns the original value, so that it can be inspected further.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a given action did not result in errors or warnings.
|
||||||
|
|
||||||
|
"foobar".write (enso_project.data / "f.txt") . should_succeed
|
||||||
|
Error.should_succeed : Boolean -> Integer -> Any
|
||||||
|
Error.should_succeed self frames_to_skip=0 =
|
||||||
|
Test.fail_match_on_unexpected_error self 1+frames_to_skip
|
||||||
|
|
||||||
|
## Asserts that the given `Boolean` is `True`
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a boolean value is true.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_true = Examples.get_boolean . should_be_true
|
||||||
|
Boolean.should_be_true : Test_Result
|
||||||
|
Boolean.should_be_true self = case self of
|
||||||
|
True -> Test_Result.Success
|
||||||
|
False ->
|
||||||
|
loc = Meta.get_source_location 2
|
||||||
|
Panic.throw (Test_Result.Failure "Expected False to be True (at "+loc+").")
|
||||||
|
|
||||||
|
## Asserts that the given `Boolean` is `True`.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a boolean value is true.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_true = Examples.get_boolean . should_be_true
|
||||||
|
Error.should_be_true : Test_Result
|
||||||
|
Error.should_be_true self = Test.fail_match_on_unexpected_error self 1
|
||||||
|
|
||||||
|
## Asserts that the given `Boolean` is `False`
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a boolean value is false.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_false = Examples.get_boolean . should_be_false
|
||||||
|
Boolean.should_be_false : Test_Result
|
||||||
|
Boolean.should_be_false self = case self of
|
||||||
|
True ->
|
||||||
|
loc = Meta.get_source_location 2
|
||||||
|
Panic.throw (Test_Result.Failure "Expected True to be False (at "+loc+").")
|
||||||
|
False -> Test_Result.Success
|
||||||
|
|
||||||
|
## Asserts that the given `Boolean` is `False`
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that a boolean value is false.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_false = Examples.get_boolean . should_be_false
|
||||||
|
Error.should_be_false : Test_Result
|
||||||
|
Error.should_be_false self = Test.fail_match_on_unexpected_error self 1
|
||||||
|
|
||||||
|
## Asserts that a value is of a given type.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- typ: The type to assert that `self` is a value of.
|
||||||
|
|
||||||
|
> Examples
|
||||||
|
Assert that 1 is of type Boolean.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_a = 1.should_be_a Boolean
|
||||||
|
Any.should_be_a : Any -> Test_Result
|
||||||
|
Any.should_be_a self typ = if self.is_a typ || self==typ then Test_Result.Success else
|
||||||
|
loc = Meta.get_source_location 0
|
||||||
|
expected_type = Meta.get_qualified_type_name typ
|
||||||
|
actual_type = Meta.get_qualified_type_name self
|
||||||
|
message = "Expected a value of type " + expected_type + " but got a value of type " + actual_type + " instead (at " + loc + ")."
|
||||||
|
Panic.throw <| Test_Result.Failure message
|
||||||
|
|
||||||
|
## Asserts that a value is of a given type.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- typ: The type to assert that `self` is a value of.
|
||||||
|
|
||||||
|
> Examples
|
||||||
|
Assert that 1 is of type Integer.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_be_an = 1.should_be_an Integer
|
||||||
|
Any.should_be_an : Any -> Test_Result
|
||||||
|
Any.should_be_an self typ = self.should_be_a typ
|
||||||
|
|
||||||
|
## Asserts that `self` value contains the same elements as `that`.
|
||||||
|
|
||||||
|
It only checks that all elements from one collection are also present in the
|
||||||
|
other one. Arities of elements are not checked, so the collections can still
|
||||||
|
differ in length by containing duplicate elements.
|
||||||
|
|
||||||
|
It will work on any collection which supports the methods
|
||||||
|
`each : (Any -> Nothing) -> Any` and `contains : Any -> Boolean`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- that: The collection to compare.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one vector should contain the same elements as another.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = [1, 2] . should_contain_the_same_elements_as [2, 1]
|
||||||
|
Any.should_contain_the_same_elements_as : Any -> Integer -> Test_Result
|
||||||
|
Any.should_contain_the_same_elements_as self that frames_to_skip=0 =
|
||||||
|
loc = Meta.get_source_location 1+frames_to_skip
|
||||||
|
that.each element->
|
||||||
|
if self.contains element . not then
|
||||||
|
msg = "The collection (" + self.to_text + ") did not contain "+element.to_text+" (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
self.each element->
|
||||||
|
if that.contains element . not then
|
||||||
|
msg = "The collection contained an element ("+element.to_text+") which was not expected (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Asserts that `self` value contains the same elements as `that`.
|
||||||
|
|
||||||
|
It only checks that all elements from one collection are also present in the
|
||||||
|
other one. Arities of elements are not checked, so the collections can still
|
||||||
|
differ in length by containing duplicate elements.
|
||||||
|
|
||||||
|
It will work on any collection which supports the methods
|
||||||
|
`each : (Any -> Nothing) -> Any` and `contains : Any -> Boolean`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- _: The collection to compare.
|
||||||
|
- frames_to_skip (optional, advanced): used to alter the location which is
|
||||||
|
displayed as the source of this error.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Assert that one vector should contain the same elements as another.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_should_equal = [1, 2] . should_contain_the_same_elements_as [2, 1]
|
||||||
|
Error.should_contain_the_same_elements_as : Any -> Test_Result
|
||||||
|
Error.should_contain_the_same_elements_as self _ frames_to_skip=0 = Test.fail_match_on_unexpected_error self 1+frames_to_skip
|
@ -3,22 +3,24 @@ from Standard.Base import all
|
|||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
polyglot java import org.enso.base.Text_Utils
|
polyglot java import org.enso.base.Text_Utils
|
||||||
|
|
||||||
upper_case_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".char_vector
|
## Object to generate (deterministic) random value for testing
|
||||||
lower_case_letters = "abcdefghijklmnopqrstuvwxyz".char_vector
|
type Faker
|
||||||
numbers = "0123456789".char_vector
|
upper_case_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".char_vector
|
||||||
|
|
||||||
## Creates a new Faker which can be used for creating test values.
|
lower_case_letters = "abcdefghijklmnopqrstuvwxyz".char_vector
|
||||||
|
|
||||||
|
numbers = "0123456789".char_vector
|
||||||
|
|
||||||
|
## Creates a new Faker which can be used for creating test values.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- seed: Optional seed value to make the sequence deterministic
|
- seed: Optional seed value to make the sequence deterministic
|
||||||
new : Integer -> Faker
|
new : Integer -> Faker
|
||||||
new (seed = 0) =
|
new (seed = 0) =
|
||||||
generator = if seed == 0 then Random.new else Random.new seed
|
generator = if seed == 0 then Random.new else Random.new seed
|
||||||
Faker generator
|
Faker.Value generator
|
||||||
|
|
||||||
## Object to generate (deterministic) random value for testing
|
Value generator
|
||||||
type Faker
|
|
||||||
type Faker generator
|
|
||||||
|
|
||||||
## Creates a random Text based on a template of character sets.
|
## Creates a random Text based on a template of character sets.
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ type Faker
|
|||||||
- upper_case: use upper_case letters
|
- upper_case: use upper_case letters
|
||||||
alpha : Integer -> Boolean -> Text
|
alpha : Integer -> Boolean -> Text
|
||||||
alpha self length=1 upper_case=False =
|
alpha self length=1 upper_case=False =
|
||||||
alphabet = if upper_case then upper_case_letters else lower_case_letters
|
alphabet = if upper_case then Faker.upper_case_letters else Faker.lower_case_letters
|
||||||
self.string_value <| 0.up_to length . map _->alphabet
|
self.string_value <| 0.up_to length . map _->alphabet
|
||||||
|
|
||||||
## Generates a Text consisting of lower/upper case characters and digits.
|
## Generates a Text consisting of lower/upper case characters and digits.
|
||||||
@ -58,7 +60,7 @@ type Faker
|
|||||||
- upper_case: use upper_case letters
|
- upper_case: use upper_case letters
|
||||||
alpha_numeric : Integer -> Boolean -> Text
|
alpha_numeric : Integer -> Boolean -> Text
|
||||||
alpha_numeric self length=1 upper_case=False =
|
alpha_numeric self length=1 upper_case=False =
|
||||||
alphabet = (if upper_case then upper_case_letters else lower_case_letters) + numbers
|
alphabet = (if upper_case then Faker.upper_case_letters else Faker.lower_case_letters) + Faker.numbers
|
||||||
self.string_value <| 0.up_to length . map _->alphabet
|
self.string_value <| 0.up_to length . map _->alphabet
|
||||||
|
|
||||||
## Generates a Text for a hexadecimal number
|
## Generates a Text for a hexadecimal number
|
||||||
|
@ -1,892 +1,15 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base.Data.Time.Duration
|
|
||||||
import Standard.Base.Runtime.State
|
|
||||||
import Standard.Base.System
|
|
||||||
|
|
||||||
polyglot java import java.lang.NullPointerException
|
import project.Bench.Bench
|
||||||
polyglot java import java.lang.StringBuilder
|
import project.Faker.Faker
|
||||||
|
import project.Problems
|
||||||
## Creates a new test group, describing properties of the object
|
import project.Test_Suite.Test_Suite
|
||||||
described by `self`.
|
import project.Test.Test
|
||||||
|
import project.Extensions
|
||||||
Arguments:
|
|
||||||
- specs: An action encapsulating a number of test specs or groups.
|
export project.Bench.Bench
|
||||||
|
export project.Faker.Faker
|
||||||
> Example
|
export project.Problems
|
||||||
Building a basic test suite.
|
export project.Test_Suite.Test_Suite
|
||||||
|
export project.Test.Test
|
||||||
import Standard.Test
|
export project.Extensions
|
||||||
|
|
||||||
example_run_main = Test.Suite.run_main <|
|
|
||||||
Test.group "Number" <|
|
|
||||||
Test.specify "should define addition" <|
|
|
||||||
2+3 . should_equal 5
|
|
||||||
Test.specify "should define multiplication" <|
|
|
||||||
2*3 . should_equal 6
|
|
||||||
Suite.run_main : Any -> Nothing
|
|
||||||
Suite.run_main ~specs =
|
|
||||||
config = config_from_env
|
|
||||||
r = Suite.run specs config
|
|
||||||
code = if r.is_fail then 1 else 0
|
|
||||||
System.exit code
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
find_project_root : File -> File
|
|
||||||
find_project_root path =
|
|
||||||
if path.is_nothing then Nothing else
|
|
||||||
handler _ = Nothing
|
|
||||||
Panic.catch NullPointerException handler=handler <|
|
|
||||||
if path.name == "src" then path.parent else
|
|
||||||
@Tail_Call find_project_root path.parent
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
find_caller_script : [Stack_Trace_Element] -> File
|
|
||||||
find_caller_script stack =
|
|
||||||
find_main idx =
|
|
||||||
if stack.at idx . name == "Suite.type.run_main" then idx else
|
|
||||||
@Tail_Call find_main (idx + 1)
|
|
||||||
main_index = find_main 0
|
|
||||||
|
|
||||||
find_caller idx =
|
|
||||||
source = stack.at idx . source_location
|
|
||||||
if source.is_a Source_Location_Data then stack.at idx . source_location . file else
|
|
||||||
if (idx + 1 == stack.length) then Nothing else
|
|
||||||
@Tail_Call find_caller (idx + 1)
|
|
||||||
|
|
||||||
find_caller (main_index + 1)
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Creates an Suite_Config based off environment and caller location
|
|
||||||
config_from_env : Suite_Config
|
|
||||||
config_from_env =
|
|
||||||
only_group_regexp = Environment.get "TEST_ONLY_GROUP"
|
|
||||||
print_only_failures = Environment.get "REPORT_ONLY_FAILED" != Nothing
|
|
||||||
junit_folder = Environment.get "ENSO_TEST_JUNIT_DIR"
|
|
||||||
results_path = if junit_folder.is_nothing then Nothing else
|
|
||||||
caller_script = find_caller_script Runtime.get_stack_trace
|
|
||||||
project_root = find_project_root caller_script
|
|
||||||
case project_root.is_nothing of
|
|
||||||
True ->
|
|
||||||
IO.println "Unable to determine root project path. JUnit output disabled."
|
|
||||||
Nothing
|
|
||||||
False ->
|
|
||||||
(File.new junit_folder) / project_root.name / "JUnit.xml"
|
|
||||||
|
|
||||||
Suite_Config_Data only_group_regexp print_only_failures results_path
|
|
||||||
|
|
||||||
|
|
||||||
## Creates a new test group, describing properties of the object
|
|
||||||
described by `self`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- specs: An action encapsulating a number of test specs or groups.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Building a basic test suite.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_run = Test.Suite.run <|
|
|
||||||
Test.group "Number" <|
|
|
||||||
Test.specify "should define addition" <|
|
|
||||||
2+3 . should_equal 5
|
|
||||||
Test.specify "should define multiplication" <|
|
|
||||||
2*3 . should_equal 6
|
|
||||||
Suite.run : Any -> Suite_Config -> Any
|
|
||||||
Suite.run ~specs config =
|
|
||||||
builder = if config.should_output_junit then StringBuilder.new else Nothing
|
|
||||||
wrap_junit_testsuites config builder <|
|
|
||||||
State.run Suite (Suite_Data config Nil builder) <|
|
|
||||||
specs
|
|
||||||
State.get Suite
|
|
||||||
|
|
||||||
|
|
||||||
## Creates a new test group, describing properties of the object
|
|
||||||
described by `self`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- name: The name of the test group.
|
|
||||||
- behaviors: An action containing a set of specs for the group.
|
|
||||||
- pending: A reason for why the test is pending, or `Nothing` when it is not
|
|
||||||
pending.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Adding a test group.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_group = Test.Suite.run <|
|
|
||||||
Test.group "Number" <| Nothing
|
|
||||||
group : Text -> Any -> (Text | Nothing) -> Nothing
|
|
||||||
group name ~behaviors pending=Nothing =
|
|
||||||
suite = State.get Suite
|
|
||||||
config = suite.config
|
|
||||||
if config.should_run_group name then
|
|
||||||
case pending of
|
|
||||||
Nothing ->
|
|
||||||
r = State.run Spec (Spec_Data name Nil) <|
|
|
||||||
behaviors
|
|
||||||
State.get Spec
|
|
||||||
r.print_report config suite.builder
|
|
||||||
new_suite = Suite_Data suite.config (Cons r suite.specs) suite.builder
|
|
||||||
State.put Suite new_suite
|
|
||||||
reason ->
|
|
||||||
report_pending_group name reason config suite.builder
|
|
||||||
|
|
||||||
## Specifies a single behavior, described by `self`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- label: A description of the behavior being tested.
|
|
||||||
- behavior: An action that executes tests.
|
|
||||||
- pending: A reason for why the test is pending, or `Nothing` when it is not
|
|
||||||
pending.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Adding a specification to the test group.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_group = Test.Suite.run <|
|
|
||||||
Test.group "Number" <|
|
|
||||||
Test.specify "should define addition" <|
|
|
||||||
2+3 . should_equal 5
|
|
||||||
> Example
|
|
||||||
Adding a pending specification to the test group.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_group = Test.Suite.run <|
|
|
||||||
Test.group "Number" <|
|
|
||||||
Test.specify "should define addition" pending="Reason" <|
|
|
||||||
2+3 . should_equal 5
|
|
||||||
specify : Text -> Any -> (Text | Nothing) -> Nothing
|
|
||||||
specify label ~behavior pending=Nothing =
|
|
||||||
pair = case pending of
|
|
||||||
Nothing -> Duration.time_execution (run_spec behavior)
|
|
||||||
reason -> Pair_Data Duration.zero (Pending reason)
|
|
||||||
result = pair.second
|
|
||||||
time_taken = pair.first
|
|
||||||
spec = State.get Spec
|
|
||||||
new_spec = Spec_Data spec.name (Cons (Behavior_Data label result time_taken) spec.behaviors)
|
|
||||||
State.put Spec new_spec
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Asserts a property about the receiver.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- verb: The property (see `Verbs`) being asserted
|
|
||||||
- argument: The argument to the verb.
|
|
||||||
Any.should : (Verbs -> Any -> Any) -> Any -> Assertion
|
|
||||||
Any.should self verb argument = verb Verbs self argument
|
|
||||||
|
|
||||||
## Fail a test with the given message.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- message: The message printed when failing the test.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Failing a test manually.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_fail = Test.fail "Something went wrong."
|
|
||||||
fail : Text -> Assertion
|
|
||||||
fail message details=Nothing =
|
|
||||||
failure = Failure message details
|
|
||||||
Panic.throw failure
|
|
||||||
|
|
||||||
## Expect a function to fail with the provided dataflow error.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- matcher: The expected type of dataflow error contained in `self`.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a computation should return an error of a given type.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_fail_with =
|
|
||||||
Examples.throw_error . should_fail_with Examples.My_Error
|
|
||||||
Any.should_fail_with : Any -> Integer -> Assertion
|
|
||||||
Any.should_fail_with self matcher frames_to_skip=0 =
|
|
||||||
loc = Meta.get_source_location 1+frames_to_skip
|
|
||||||
fail ("Expected an error " + matcher.to_text + " but no error occurred, instead got: " + self.to_text + " (at " + loc + ").")
|
|
||||||
|
|
||||||
## Expect a function to fail with the provided dataflow error.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- matcher: The expected type of dataflow error contained in `self`.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a computation should return an error of a given type.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_fail_with =
|
|
||||||
Examples.throw_error . should_fail_with Examples.My_Error
|
|
||||||
Error.should_fail_with : Any -> Integer -> Assertion
|
|
||||||
Error.should_fail_with self matcher frames_to_skip=0 =
|
|
||||||
caught = self.catch
|
|
||||||
if caught.is_a matcher then Nothing else
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
fail ("Expected error "+matcher.to_text+", but error " + caught.to_text + " has been returned (at " + loc + ").")
|
|
||||||
|
|
||||||
## Expect a function to fail with the provided panic.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- action: The action to evaluate that is expected to fail with a panic.
|
|
||||||
- matcher: The expected type of the panic thrown by `action`.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Expect that a computation should panic as part of a test.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_expect_panic_with =
|
|
||||||
Test.expect_panic_with Examples.throw_panic Examples.My_Error
|
|
||||||
expect_panic_with : Any -> Any -> Assertion
|
|
||||||
expect_panic_with ~action matcher =
|
|
||||||
res = Panic.recover Any action
|
|
||||||
case res of
|
|
||||||
_ ->
|
|
||||||
loc = Meta.get_source_location 2
|
|
||||||
return_suffix = if res.is_nothing then "" else "and returned ["+res.to_text+"]"
|
|
||||||
fail ("Expected a " + matcher.to_text + " to be thrown, but the action succeeded " + return_suffix + " (at "+loc+").")
|
|
||||||
err = res.catch
|
|
||||||
if err.is_a matcher then Nothing else
|
|
||||||
fail ("Expected a " + matcher.to_text + ", but " + err.to_text + " was thrown instead.")
|
|
||||||
|
|
||||||
## Asserts that `self` value is equal to the expected value.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The value to check `self` for equality with.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that one value should equal another,
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = Examples.add_1_to 1 . should_equal 2
|
|
||||||
Any.should_equal : Any -> Integer -> Assertion
|
|
||||||
Any.should_equal self that frames_to_skip=0 = case self == that of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = self.to_text + " did not equal " + that.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value is equal to the expected type value.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The type to check `self` for equality with.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that some type is equal to another.,
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = Examples.some_tpe . should_equal_tpe Vector.Vector
|
|
||||||
Any.should_equal_type : Any -> Integer -> Assertion
|
|
||||||
Any.should_equal_type self that frames_to_skip=0 = case (self.is_same_object_as that) of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = self.to_text + " did not equal type " + that.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value is not equal to the expected value.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The value to check `self` for equality with.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that one value should equal another,
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_not_equal = Examples.add_1_to 1 . should_not_equal 2
|
|
||||||
Any.should_not_equal : Any -> Integer -> Assertion
|
|
||||||
Any.should_not_equal self that frames_to_skip=0 = case self != that of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = self.to_text + " did equal " + that.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value is not equal to the expected type value.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The type to check `self` for equality with.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that some type is equal to another.,
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_not_equal = Examples.some_tpe . should_not_equal_tpe Vector.Vector
|
|
||||||
Any.should_not_equal_type : Any -> Integer -> Assertion
|
|
||||||
Any.should_not_equal_type self that frames_to_skip=0 = case (self.is_same_object_as that . not) of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = self.to_text + " did equal type " + that.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value is equal to the expected value.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- _: The value to check `self` for equality with.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that one value should equal another,
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = Examples.add_1_to 1 . should_equal 2
|
|
||||||
Error.should_equal : Any -> Assertion
|
|
||||||
Error.should_equal self _ frames_to_skip=0 = fail_match_on_unexpected_error self 1+frames_to_skip
|
|
||||||
|
|
||||||
## Asserts that `self` is within `epsilon` from `that`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The value to compare `self` for equality with.
|
|
||||||
- epsilon: The epislon for comparing two decimal numbers.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Compare two decimal values.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = 1.1 . should_equal 1.1
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Compare two decimal values with an epsilon (tolerance).
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal =
|
|
||||||
1.00000001 . should_equal 1.00000002 epsilon=0.0001
|
|
||||||
Number.should_equal : Decimal -> Decimal -> Integer -> Assertion
|
|
||||||
Number.should_equal self that epsilon=0 frames_to_skip=0 =
|
|
||||||
matches = case that of
|
|
||||||
_ : Number -> self.equals that epsilon
|
|
||||||
_ -> False
|
|
||||||
case matches of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = self.to_text + " did not equal " + that.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value is not an error.
|
|
||||||
|
|
||||||
It returns the original value, so that it can be inspected further.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a given action did not result in errors or warnings.
|
|
||||||
|
|
||||||
"foobar".write (enso_project.data / "f.txt") . should_succeed
|
|
||||||
Any.should_succeed : Boolean -> Integer -> Any
|
|
||||||
Any.should_succeed self frames_to_skip=0 =
|
|
||||||
_ = frames_to_skip
|
|
||||||
self
|
|
||||||
|
|
||||||
## Asserts that `self` value is not an error.
|
|
||||||
|
|
||||||
It returns the original value, so that it can be inspected further.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a given action did not result in errors or warnings.
|
|
||||||
|
|
||||||
"foobar".write (enso_project.data / "f.txt") . should_succeed
|
|
||||||
Error.should_succeed : Boolean -> Integer -> Any
|
|
||||||
Error.should_succeed self frames_to_skip=0 =
|
|
||||||
fail_match_on_unexpected_error self 1+frames_to_skip
|
|
||||||
|
|
||||||
## Checks that the provided action returns without any errors or warnings.
|
|
||||||
|
|
||||||
If you just want to check for errors, usage of the `.should_succeed`
|
|
||||||
extension function is preferred.
|
|
||||||
assert_no_problems value frames_to_skip=0 =
|
|
||||||
value.catch Any _->
|
|
||||||
fail_match_on_unexpected_error value 2+frames_to_skip
|
|
||||||
warnings = Warning.get_all value . map .value
|
|
||||||
if warnings.not_empty then
|
|
||||||
loc = Meta.get_source_location 2+frames_to_skip
|
|
||||||
msg = "The action returned unexpected warnings: " + warnings.to_text + " (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that the given `Boolean` is `True`
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a boolean value is true.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_true = Examples.get_boolean . should_be_true
|
|
||||||
Boolean.should_be_true : Assertion
|
|
||||||
Boolean.should_be_true self = case self of
|
|
||||||
True -> Success
|
|
||||||
False ->
|
|
||||||
loc = Meta.get_source_location 2
|
|
||||||
Panic.throw (Failure "Expected False to be True (at "+loc+").")
|
|
||||||
|
|
||||||
## Asserts that the given `Boolean` is `True`.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a boolean value is true.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_true = Examples.get_boolean . should_be_true
|
|
||||||
Error.should_be_true : Assertion
|
|
||||||
Error.should_be_true self = fail_match_on_unexpected_error self 1
|
|
||||||
|
|
||||||
## Asserts that the given `Boolean` is `False`
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a boolean value is false.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_false = Examples.get_boolean . should_be_false
|
|
||||||
Boolean.should_be_false : Assertion
|
|
||||||
Boolean.should_be_false self = case self of
|
|
||||||
True ->
|
|
||||||
loc = Meta.get_source_location 2
|
|
||||||
Panic.throw (Failure "Expected True to be False (at "+loc+").")
|
|
||||||
False -> Success
|
|
||||||
|
|
||||||
## Asserts that the given `Boolean` is `False`
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that a boolean value is false.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_false = Examples.get_boolean . should_be_false
|
|
||||||
Error.should_be_false : Assertion
|
|
||||||
Error.should_be_false self = fail_match_on_unexpected_error self 1
|
|
||||||
|
|
||||||
## Asserts that a value is of a given type.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- typ: The type to assert that `self` is a value of.
|
|
||||||
|
|
||||||
> Examples
|
|
||||||
Assert that 1 is of type Boolean.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_a = 1.should_be_a Boolean
|
|
||||||
Any.should_be_a : Any -> Assertion
|
|
||||||
Any.should_be_a self typ = if self.is_a typ || self==typ then Success else
|
|
||||||
loc = Meta.get_source_location 0
|
|
||||||
expected_type = Meta.get_qualified_type_name typ
|
|
||||||
actual_type = Meta.get_qualified_type_name self
|
|
||||||
message = "Expected a value of type " + expected_type + " but got a value of type " + actual_type + " instead (at " + loc + ")."
|
|
||||||
Panic.throw <| Failure message
|
|
||||||
|
|
||||||
## Asserts that a value is of a given type.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- typ: The type to assert that `self` is a value of.
|
|
||||||
|
|
||||||
> Examples
|
|
||||||
Assert that 1 is of type Integer.
|
|
||||||
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_be_an = 1.should_be_an Integer
|
|
||||||
Any.should_be_an : Any -> Assertion
|
|
||||||
Any.should_be_an self typ = self.should_be_a typ
|
|
||||||
|
|
||||||
## Asserts that `self` value contains the same elements as `that`.
|
|
||||||
|
|
||||||
It only checks that all elements from one collection are also present in the
|
|
||||||
other one. Arities of elements are not checked, so the collections can still
|
|
||||||
differ in length by containing duplicate elements.
|
|
||||||
|
|
||||||
It will work on any collection which supports the methods
|
|
||||||
`each : (Any -> Nothing) -> Any` and `contains : Any -> Boolean`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- that: The collection to compare.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that one vector should contain the same elements as another.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = [1, 2] . should_contain_the_same_elements_as [2, 1]
|
|
||||||
Any.should_contain_the_same_elements_as : Any -> Integer -> Assertion
|
|
||||||
Any.should_contain_the_same_elements_as self that frames_to_skip=0 =
|
|
||||||
loc = Meta.get_source_location 1+frames_to_skip
|
|
||||||
that.each element->
|
|
||||||
if self.contains element . not then
|
|
||||||
msg = "The collection (" + self.to_text + ") did not contain "+element.to_text+" (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
self.each element->
|
|
||||||
if that.contains element . not then
|
|
||||||
msg = "The collection contained an element ("+element.to_text+") which was not expected (at " + loc + ")."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## Asserts that `self` value contains the same elements as `that`.
|
|
||||||
|
|
||||||
It only checks that all elements from one collection are also present in the
|
|
||||||
other one. Arities of elements are not checked, so the collections can still
|
|
||||||
differ in length by containing duplicate elements.
|
|
||||||
|
|
||||||
It will work on any collection which supports the methods
|
|
||||||
`each : (Any -> Nothing) -> Any` and `contains : Any -> Boolean`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- _: The collection to compare.
|
|
||||||
- frames_to_skip (optional, advanced): used to alter the location which is
|
|
||||||
displayed as the source of this error.
|
|
||||||
|
|
||||||
> Example
|
|
||||||
Assert that one vector should contain the same elements as another.
|
|
||||||
|
|
||||||
import Standard.Examples
|
|
||||||
import Standard.Test
|
|
||||||
|
|
||||||
example_should_equal = [1, 2] . should_contain_the_same_elements_as [2, 1]
|
|
||||||
Error.should_contain_the_same_elements_as : Any -> Assertion
|
|
||||||
Error.should_contain_the_same_elements_as self _ frames_to_skip=0 = fail_match_on_unexpected_error self 1+frames_to_skip
|
|
||||||
|
|
||||||
|
|
||||||
type Verbs
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the `subject` starts with `argument`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- subject: The value to check. It must have a `.starts_with` method.
|
|
||||||
- argument: The expected prefix.
|
|
||||||
start_with : Text -> Text -> Assertion
|
|
||||||
start_with self subject argument =
|
|
||||||
if subject.starts_with argument then Success else
|
|
||||||
fail (subject.to_text + " did not start with " + argument.to_text)
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the `subject` is equal to the `argument`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- subject: The value to check for equality against the provided value.
|
|
||||||
- argument: The provided value to check the `subject` for equality
|
|
||||||
against.
|
|
||||||
equal : Any -> Any -> Assertion
|
|
||||||
equal self subject argument =
|
|
||||||
if subject == argument then Success else
|
|
||||||
msg = subject.to_text + " did not equal " + argument.to_text + "."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if `subject` is `argument`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- subject: The value to check for equality against the provided value.
|
|
||||||
- argument: The provided value to check the `subject` for equality
|
|
||||||
against.
|
|
||||||
be : Any -> Any -> Assertion
|
|
||||||
be self subject argument = self.equal subject argument
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if `subject` contains `argument`.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- subject: The collection type to check if `argument` is contained in it.
|
|
||||||
This type must have a `.contains` method.
|
|
||||||
- argument: The value to see if it is contained in `subject`.
|
|
||||||
contain : Any -> Any -> Assertion
|
|
||||||
contain self subject argument =
|
|
||||||
if subject.contains argument then Success else
|
|
||||||
msg = subject.to_text + " did not contain " + argument.to_text + "."
|
|
||||||
fail msg
|
|
||||||
|
|
||||||
from project.Main.Suite_Config import all
|
|
||||||
|
|
||||||
## PRVATE
|
|
||||||
type Suite_Config
|
|
||||||
Suite_Config_Data only_group_regexp print_only_failures output_path
|
|
||||||
|
|
||||||
should_run_group self name =
|
|
||||||
regexp = self.only_group_regexp
|
|
||||||
case regexp of
|
|
||||||
_ : Text -> name.matches regexp . catch Any (_->True)
|
|
||||||
_ -> True
|
|
||||||
|
|
||||||
should_output_junit self =
|
|
||||||
self.output_path.is_nothing.not
|
|
||||||
|
|
||||||
from project.Main.Suite import all
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
The top-level entry point for a test suite.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- config: Suite_Config controlloing the test run.
|
|
||||||
- specs: The specs contained within the test suite.
|
|
||||||
- builder: StringBuilder for JUnit output.
|
|
||||||
type Suite
|
|
||||||
Suite_Data config specs builder
|
|
||||||
|
|
||||||
from project.Main.Spec import all
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
A group of behaviors for a test.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- name: The name of the spec.
|
|
||||||
- behaviors: The results of the behaviors encapsulated in that spec.
|
|
||||||
type Spec
|
|
||||||
Spec_Data name behaviors
|
|
||||||
|
|
||||||
from project.Main.Behavior import all
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
A description of a behaviors in a test.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- name: The name of the behavior.
|
|
||||||
- result: The result of the behavior.
|
|
||||||
- time_taken: The duration that the behaviour took to run.
|
|
||||||
type Behavior
|
|
||||||
Behavior_Data name result time_taken
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the behavior is a failure.
|
|
||||||
Behavior.is_fail : Boolean
|
|
||||||
Behavior.is_fail self = self.result.is_fail
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the spec group contains any failures and hence fails itself.
|
|
||||||
Spec.is_fail : Boolean
|
|
||||||
Spec.is_fail self = self.behaviors.any .is_fail
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the suite contains any failures, and hence fails itself.
|
|
||||||
Suite.is_fail : Boolean
|
|
||||||
Suite.is_fail self = self.specs.any .is_fail
|
|
||||||
|
|
||||||
from project.Main.Finished_With_Error import all
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
An error describing that a test finished with an unexpected error.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- err: The payload of the error that triggered this error.
|
|
||||||
- stack_trace_text: A textual representation of the stack trace for the
|
|
||||||
error.
|
|
||||||
type Finished_With_Error
|
|
||||||
Finished_With_Error_Data err stack_trace_text
|
|
||||||
|
|
||||||
from project.Main.Assertion import all
|
|
||||||
from project.Main.Assertion export all
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
type Assertion
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Represents a successful behavioral test.
|
|
||||||
Success
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Represents a failing behavioral test.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- message: The reason why the test failed.
|
|
||||||
- details: Additional context of the error, for example the stack trace.
|
|
||||||
Failure message details
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Represents a pending behavioral test.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- reason: Text describing why the test is pending.
|
|
||||||
Pending reason
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Checks if the Assertion is a failure.
|
|
||||||
is_fail : Boolean
|
|
||||||
is_fail self = case self of
|
|
||||||
Success -> False
|
|
||||||
Failure _ _ -> True
|
|
||||||
Pending _ -> False
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
|
|
||||||
Executes a behavior test.
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- behavior: The behavior to execute.
|
|
||||||
run_spec : Any -> Assertion
|
|
||||||
run_spec ~behavior =
|
|
||||||
recovery = Panic.recover Any <|
|
|
||||||
result = behavior
|
|
||||||
result.catch Any err->
|
|
||||||
Panic.throw (Finished_With_Error_Data err result.get_stack_trace_text)
|
|
||||||
Nothing
|
|
||||||
maybeExc = case recovery of
|
|
||||||
_ -> Success
|
|
||||||
result = maybeExc.catch Any ex->
|
|
||||||
case ex of
|
|
||||||
Failure _ _ -> ex
|
|
||||||
Finished_With_Error_Data err stack_trace_text ->
|
|
||||||
Failure ("An unexpected error was returned: " + err.to_text) details=stack_trace_text
|
|
||||||
_ -> Failure ("An unexpected panic was thrown: " + ex.to_text) details=maybeExc.get_stack_trace_text
|
|
||||||
result
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Reports an unexpected dataflow error has occurred.
|
|
||||||
fail_match_on_unexpected_error : Error -> Integer -> Nothing
|
|
||||||
fail_match_on_unexpected_error error frames_to_skip =
|
|
||||||
payload = error.catch
|
|
||||||
loc = Meta.get_source_location 1+frames_to_skip
|
|
||||||
msg = "An unexpected dataflow error (" + payload.to_text + ") has been matched (at " + loc + ")."
|
|
||||||
fail msg+'\n'+error.get_stack_trace_text
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Write the JUnit XML header.
|
|
||||||
wrap_junit_testsuites : Suite_Config -> (StringBuilder|Nothing) -> Any -> Nothing
|
|
||||||
wrap_junit_testsuites config builder ~action =
|
|
||||||
if config.should_output_junit then
|
|
||||||
builder.append '<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
||||||
builder.append '<testsuites>\n'
|
|
||||||
|
|
||||||
result = action
|
|
||||||
|
|
||||||
if config.should_output_junit then
|
|
||||||
builder.append '</testsuites>\n'
|
|
||||||
config.output_path.parent.create_directory
|
|
||||||
builder.toString.write config.output_path
|
|
||||||
|
|
||||||
result
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Record JUnit PENDING group.
|
|
||||||
report_pending_group : Text -> Text -> Suite_Config -> (StringBuilder|Nothing) -> Nothing
|
|
||||||
report_pending_group name reason config builder =
|
|
||||||
if config.should_output_junit then
|
|
||||||
builder.append (' <testsuite name="' + (escape_xml name) + '" timestamp="' + (Date_Time.now.format "yyyy-MM-dd'T'HH:mm:ss") + '" time="0">\n')
|
|
||||||
builder.append (' <testcase name="' + (escape_xml name) + '"><skipped message="' + (escape_xml reason) + '" /></testcase>\n')
|
|
||||||
builder.append ' </testsuite>\n'
|
|
||||||
|
|
||||||
IO.println ("[PENDING] " + name)
|
|
||||||
IO.println (" Reason: " + reason)
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Prints a report on the tests to standard output.
|
|
||||||
Spec.print_report : Suite_Config -> (StringBuilder|Nothing) -> Nothing
|
|
||||||
Spec.print_report self config builder =
|
|
||||||
total_time = self.behaviors.fold Duration.zero acc-> behavior->
|
|
||||||
acc + behavior.time_taken
|
|
||||||
if config.should_output_junit then
|
|
||||||
builder.append (' <testsuite name="' + (escape_xml self.name) + '" timestamp="' + (Date_Time.now.format "yyyy-MM-dd'T'HH:mm:ss") + '"')
|
|
||||||
builder.append (' tests="' + self.behaviors.length.to_text + '"')
|
|
||||||
builder.append (' disabled="' + self.behaviors.filter (x->(x.is_a Pending)) . length . to_text + '"')
|
|
||||||
builder.append (' errors="' + self.behaviors.filter (x->(x.is_a Failure)) . length . to_text + '"')
|
|
||||||
builder.append (' time="' + (total_time.total_seconds).to_text + '"')
|
|
||||||
builder.append ('>\n')
|
|
||||||
|
|
||||||
self.behaviors.reverse.each behavior->
|
|
||||||
builder.append (' <testcase name="' + (escape_xml behavior.name) + '" time="' + ((behavior.time_taken.total_milliseconds / 1000.0).to_text) + '">')
|
|
||||||
case behavior.result of
|
|
||||||
Success -> Nothing
|
|
||||||
Failure msg details ->
|
|
||||||
escaped_message = escape_xml msg . replace '\n' ' '
|
|
||||||
builder.append ('\n <error message="' + escaped_message + '">\n')
|
|
||||||
if details.is_nothing.not then
|
|
||||||
## We duplicate the message, because sometimes the
|
|
||||||
attribute is skipped if the node has any content.
|
|
||||||
builder.append (escape_xml msg)
|
|
||||||
builder.append '\n'
|
|
||||||
builder.append (escape_xml details)
|
|
||||||
builder.append '</error>\n'
|
|
||||||
Pending msg -> builder.append ('\n <skipped message="' + (escape_xml msg) + '"/>\n ')
|
|
||||||
builder.append '</testcase>\n'
|
|
||||||
builder.append ' </testsuite>\n'
|
|
||||||
|
|
||||||
should_print_behavior = config.print_only_failures.not || self.behaviors.any (b -> b.result.is_a Failure)
|
|
||||||
if should_print_behavior then
|
|
||||||
IO.println (self.name + ": [" + total_time.total_milliseconds.to_text + "ms]")
|
|
||||||
self.behaviors.reverse.each behavior->
|
|
||||||
case behavior.result of
|
|
||||||
Success ->
|
|
||||||
if config.print_only_failures.not then
|
|
||||||
IO.println (" - " + behavior.name + " [" + behavior.time_taken.total_milliseconds.to_text + "ms]")
|
|
||||||
Failure msg details ->
|
|
||||||
IO.println (" - [FAILED] " + behavior.name + " [" + behavior.time_taken.total_milliseconds.to_text + "ms]")
|
|
||||||
IO.println (" Reason: " + msg)
|
|
||||||
if details.is_nothing.not then
|
|
||||||
IO.println details
|
|
||||||
Pending reason ->
|
|
||||||
if config.print_only_failures.not then
|
|
||||||
IO.println (" - [PENDING] " + behavior.name)
|
|
||||||
IO.println (" Reason: " + reason)
|
|
||||||
|
|
||||||
|
|
||||||
## PRIVATE
|
|
||||||
Escape Text for XML
|
|
||||||
escape_xml : Text -> Text
|
|
||||||
escape_xml input =
|
|
||||||
input.replace '&' '&' . replace '"' '"' . replace "'" ''' . replace '<' '<' . replace '>' '>'
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
import project.Extensions
|
||||||
|
|
||||||
## UNSTABLE
|
## UNSTABLE
|
||||||
Tests how a specific operation behaves depending on the requested
|
Tests how a specific operation behaves depending on the requested
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
polyglot java import java.lang.NullPointerException
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
find_project_root : File -> File
|
||||||
|
find_project_root path =
|
||||||
|
if path.is_nothing then Nothing else
|
||||||
|
handler _ = Nothing
|
||||||
|
Panic.catch NullPointerException handler=handler <|
|
||||||
|
if path.name == "src" then path.parent else
|
||||||
|
@Tail_Call find_project_root path.parent
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
find_caller_script : [Stack_Trace_Element] -> File
|
||||||
|
find_caller_script stack =
|
||||||
|
find_main idx =
|
||||||
|
if stack.at idx . name == "Test_Suite.type.run_main" then idx else
|
||||||
|
@Tail_Call find_main (idx + 1)
|
||||||
|
main_index = find_main 0
|
||||||
|
|
||||||
|
find_caller idx =
|
||||||
|
source = stack.at idx . source_location
|
||||||
|
if source.is_a Source_Location_Data then stack.at idx . source_location . file else
|
||||||
|
if (idx + 1 == stack.length) then Nothing else
|
||||||
|
@Tail_Call find_caller (idx + 1)
|
||||||
|
|
||||||
|
find_caller (main_index + 1)
|
||||||
|
|
||||||
|
## Holds configuration for a Test_Suite
|
||||||
|
type Suite_Config
|
||||||
|
## Creates an Suite_Config based off environment and caller location
|
||||||
|
from_environment : Suite_Config
|
||||||
|
from_environment =
|
||||||
|
only_group_regexp = Environment.get "TEST_ONLY_GROUP"
|
||||||
|
print_only_failures = Environment.get "REPORT_ONLY_FAILED" != Nothing
|
||||||
|
junit_folder = Environment.get "ENSO_TEST_JUNIT_DIR"
|
||||||
|
results_path = if junit_folder.is_nothing then Nothing else
|
||||||
|
caller_script = find_caller_script Runtime.get_stack_trace
|
||||||
|
project_root = find_project_root caller_script
|
||||||
|
case project_root.is_nothing of
|
||||||
|
True ->
|
||||||
|
IO.println "Unable to determine root project path. JUnit output disabled."
|
||||||
|
Nothing
|
||||||
|
False ->
|
||||||
|
(File.new junit_folder) / project_root.name / "JUnit.xml"
|
||||||
|
|
||||||
|
Suite_Config.Value only_group_regexp print_only_failures results_path
|
||||||
|
|
||||||
|
## PRIVATE - construct a configuration
|
||||||
|
Value only_group_regexp print_only_failures output_path
|
||||||
|
|
||||||
|
should_run_group self name =
|
||||||
|
regexp = self.only_group_regexp
|
||||||
|
case regexp of
|
||||||
|
_ : Text -> name.matches regexp . catch Any (_->True)
|
||||||
|
_ -> True
|
||||||
|
|
||||||
|
should_output_junit self =
|
||||||
|
self.output_path.is_nothing.not
|
209
distribution/lib/Standard/Test/0.0.0-dev/src/Test.enso
Normal file
209
distribution/lib/Standard/Test/0.0.0-dev/src/Test.enso
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
import Standard.Base.Runtime.State
|
||||||
|
import Standard.Base.Data.Time.Duration
|
||||||
|
|
||||||
|
import project.Test_Reporter
|
||||||
|
import project.Test_Result.Test_Result
|
||||||
|
import project.Test_Suite.Test_Suite
|
||||||
|
|
||||||
|
type Test
|
||||||
|
## Creates a new test group, describing properties of the object
|
||||||
|
described by `self`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- name: The name of the test group.
|
||||||
|
- behaviors: An action containing a set of specs for the group.
|
||||||
|
- pending: A reason for why the test is pending, or `Nothing` when it is not
|
||||||
|
pending.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Adding a test group.
|
||||||
|
|
||||||
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
|
example_group = Test_Suite.run <|
|
||||||
|
Test.group "Number" <| Nothing
|
||||||
|
group : Text -> Any -> (Text | Nothing) -> Nothing
|
||||||
|
group name ~behaviors pending=Nothing =
|
||||||
|
suite = State.get Test_Suite
|
||||||
|
config = suite.config
|
||||||
|
if config.should_run_group name then
|
||||||
|
case pending of
|
||||||
|
Nothing ->
|
||||||
|
r = State.run Spec (Spec.Value name Nil) <|
|
||||||
|
behaviors
|
||||||
|
State.get Spec
|
||||||
|
Test_Reporter.print_report r config suite.builder
|
||||||
|
new_suite = Test_Suite.Value suite.config (Cons r suite.specs) suite.builder
|
||||||
|
State.put Test_Suite new_suite
|
||||||
|
reason ->
|
||||||
|
Test_Reporter.report_pending_group name reason config suite.builder
|
||||||
|
|
||||||
|
## Specifies a single behavior, described by `self`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- label: A description of the behavior being tested.
|
||||||
|
- behavior: An action that executes tests.
|
||||||
|
- pending: A reason for why the test is pending, or `Nothing` when it is not
|
||||||
|
pending.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Adding a specification to the test group.
|
||||||
|
|
||||||
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
|
example_group = Test_Suite.run <|
|
||||||
|
Test.group "Number" <|
|
||||||
|
Test.specify "should define addition" <|
|
||||||
|
2+3 . should_equal 5
|
||||||
|
> Example
|
||||||
|
Adding a pending specification to the test group.
|
||||||
|
|
||||||
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
|
example_group = Test_Suite.run <|
|
||||||
|
Test.group "Number" <|
|
||||||
|
Test.specify "should define addition" pending="Reason" <|
|
||||||
|
2+3 . should_equal 5
|
||||||
|
specify : Text -> Any -> (Text | Nothing) -> Nothing
|
||||||
|
specify label ~behavior pending=Nothing =
|
||||||
|
pair = case pending of
|
||||||
|
Nothing -> Duration.time_execution (run_spec behavior)
|
||||||
|
reason -> Pair_Data Duration.zero (Test_Result.Pending reason)
|
||||||
|
result = pair.second
|
||||||
|
time_taken = pair.first
|
||||||
|
spec = State.get Spec
|
||||||
|
new_spec = Spec.Value spec.name (Cons (Behavior.Value label result time_taken) spec.behaviors)
|
||||||
|
State.put Spec new_spec
|
||||||
|
|
||||||
|
## Expect a function to fail with the provided panic.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- action: The action to evaluate that is expected to fail with a panic.
|
||||||
|
- matcher: The expected type of the panic thrown by `action`.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Expect that a computation should panic as part of a test.
|
||||||
|
|
||||||
|
import Standard.Examples
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_expect_panic_with =
|
||||||
|
Test.expect_panic_with Examples.throw_panic Examples.My_Error
|
||||||
|
expect_panic_with : Any -> Any -> Test_Result
|
||||||
|
expect_panic_with ~action matcher =
|
||||||
|
res = Panic.recover Any action
|
||||||
|
case res of
|
||||||
|
_ ->
|
||||||
|
loc = Meta.get_source_location 2
|
||||||
|
return_suffix = if res.is_nothing then "" else "and returned ["+res.to_text+"]"
|
||||||
|
Test.fail ("Expected a " + matcher.to_text + " to be thrown, but the action succeeded " + return_suffix + " (at "+loc+").")
|
||||||
|
err = res.catch
|
||||||
|
if err.is_a matcher then Nothing else
|
||||||
|
Test.fail ("Expected a " + matcher.to_text + ", but " + err.to_text + " was thrown instead.")
|
||||||
|
|
||||||
|
|
||||||
|
## Checks that the provided action returns without any errors or warnings.
|
||||||
|
|
||||||
|
If you just want to check for errors, usage of the `.should_succeed`
|
||||||
|
extension function is preferred.
|
||||||
|
assert_no_problems value frames_to_skip=0 =
|
||||||
|
value.catch Any _->
|
||||||
|
Test.fail_match_on_unexpected_error value 2+frames_to_skip
|
||||||
|
warnings = Warning.get_all value . map .value
|
||||||
|
if warnings.not_empty then
|
||||||
|
loc = Meta.get_source_location 2+frames_to_skip
|
||||||
|
msg = "The action returned unexpected warnings: " + warnings.to_text + " (at " + loc + ")."
|
||||||
|
Test.fail msg
|
||||||
|
|
||||||
|
## Fail a test with the given message.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- message: The message printed when failing the test.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Failing a test manually.
|
||||||
|
|
||||||
|
from Standard.Test import Test
|
||||||
|
|
||||||
|
example_fail = Test.fail "Something went wrong."
|
||||||
|
fail : Text -> Test_Result
|
||||||
|
fail message details=Nothing =
|
||||||
|
failure = Test_Result.Failure message details
|
||||||
|
Panic.throw failure
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
Reports an unexpected dataflow error has occurred.
|
||||||
|
fail_match_on_unexpected_error : Error -> Integer -> Nothing
|
||||||
|
fail_match_on_unexpected_error error frames_to_skip =
|
||||||
|
payload = error.catch
|
||||||
|
loc = Meta.get_source_location 1+frames_to_skip
|
||||||
|
msg = "An unexpected dataflow error (" + payload.to_text + ") has been matched (at " + loc + ")."
|
||||||
|
Test.fail msg+'\n'+error.get_stack_trace_text
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Executes a behavior test.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- behavior: The behavior to execute.
|
||||||
|
run_spec : Any -> Test_Result
|
||||||
|
run_spec ~behavior =
|
||||||
|
recovery = Panic.recover Any <|
|
||||||
|
result = behavior
|
||||||
|
result.catch Any err->
|
||||||
|
Panic.throw (Finished_With.Error err result.get_stack_trace_text)
|
||||||
|
Nothing
|
||||||
|
maybeExc = case recovery of
|
||||||
|
_ -> Test_Result.Success
|
||||||
|
result = maybeExc.catch Any ex->
|
||||||
|
case ex of
|
||||||
|
Test_Result.Failure _ _ -> ex
|
||||||
|
Finished_With.Error err stack_trace_text ->
|
||||||
|
Test_Result.Failure ("An unexpected error was returned: " + err.to_text) details=stack_trace_text
|
||||||
|
_ -> Test_Result.Failure ("An unexpected panic was thrown: " + ex.to_text) details=maybeExc.get_stack_trace_text
|
||||||
|
result
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
An error describing that a test finished with an unexpected error.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- err: The payload of the error that triggered this error.
|
||||||
|
- stack_trace_text: A textual representation of the stack trace for the
|
||||||
|
error.
|
||||||
|
type Finished_With
|
||||||
|
Error err stack_trace_text
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
A group of behaviors for a test.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- name: The name of the spec.
|
||||||
|
- behaviors: The results of the behaviors encapsulated in that spec.
|
||||||
|
type Spec
|
||||||
|
Value name behaviors
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Checks if the spec group contains any failures and hence fails itself.
|
||||||
|
is_fail : Boolean
|
||||||
|
is_fail self = self.behaviors.any .is_fail
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
A description of a behaviors in a test.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- name: The name of the behavior.
|
||||||
|
- result: The result of the behavior.
|
||||||
|
- time_taken: The duration that the behaviour took to run.
|
||||||
|
type Behavior
|
||||||
|
Value name result time_taken
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Checks if the behavior is a failure.
|
||||||
|
is_fail : Boolean
|
||||||
|
is_fail self = self.result.is_fail
|
@ -0,0 +1,92 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
import Standard.Base.Data.Time.Duration
|
||||||
|
|
||||||
|
import project.Suite_Config.Suite_Config
|
||||||
|
import project.Test_Result.Test_Result
|
||||||
|
|
||||||
|
polyglot java import java.lang.StringBuilder
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
Write the JUnit XML header.
|
||||||
|
wrap_junit_testsuites : Suite_Config -> (StringBuilder|Nothing) -> Any -> Nothing
|
||||||
|
wrap_junit_testsuites config builder ~action =
|
||||||
|
if config.should_output_junit then
|
||||||
|
builder.append '<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||||
|
builder.append '<testsuites>\n'
|
||||||
|
|
||||||
|
result = action
|
||||||
|
|
||||||
|
if config.should_output_junit then
|
||||||
|
builder.append '</testsuites>\n'
|
||||||
|
config.output_path.parent.create_directory
|
||||||
|
builder.toString.write config.output_path
|
||||||
|
|
||||||
|
result
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
Prints a report on the tests to standard output.
|
||||||
|
print_report : Spec -> Suite_Config -> (StringBuilder|Nothing) -> Nothing
|
||||||
|
print_report spec config builder =
|
||||||
|
total_time = spec.behaviors.fold Duration.zero acc-> behavior->
|
||||||
|
acc + behavior.time_taken
|
||||||
|
if config.should_output_junit then
|
||||||
|
builder.append (' <testsuite name="' + (escape_xml spec.name) + '" timestamp="' + (Date_Time.now.format "yyyy-MM-dd'T'HH:mm:ss") + '"')
|
||||||
|
builder.append (' tests="' + spec.behaviors.length.to_text + '"')
|
||||||
|
builder.append (' disabled="' + spec.behaviors.filter (x->(x.is_a Test_Result.Pending)) . length . to_text + '"')
|
||||||
|
builder.append (' errors="' + spec.behaviors.filter (x->(x.is_a Test_Result.Failure)) . length . to_text + '"')
|
||||||
|
builder.append (' time="' + total_time.total_seconds.to_text + '"')
|
||||||
|
builder.append ('>\n')
|
||||||
|
|
||||||
|
spec.behaviors.reverse.each behavior->
|
||||||
|
builder.append (' <testcase name="' + (escape_xml behavior.name) + '" time="' + ((behavior.time_taken.total_milliseconds / 1000.0).to_text) + '">')
|
||||||
|
case behavior.result of
|
||||||
|
Test_Result.Success -> Nothing
|
||||||
|
Test_Result.Failure msg details ->
|
||||||
|
escaped_message = escape_xml msg . replace '\n' ' '
|
||||||
|
builder.append ('\n <error message="' + escaped_message + '">\n')
|
||||||
|
if details.is_nothing.not then
|
||||||
|
## We duplicate the message, because sometimes the
|
||||||
|
attribute is skipped if the node has any content.
|
||||||
|
builder.append (escape_xml msg)
|
||||||
|
builder.append '\n'
|
||||||
|
builder.append (escape_xml details)
|
||||||
|
builder.append '</error>\n'
|
||||||
|
Test_Result.Pending msg -> builder.append ('\n <skipped message="' + (escape_xml msg) + '"/>\n ')
|
||||||
|
builder.append '</testcase>\n'
|
||||||
|
builder.append ' </testsuite>\n'
|
||||||
|
|
||||||
|
should_print_behavior = config.print_only_failures.not || spec.behaviors.any (b -> b.result.is_a Test_Result.Failure)
|
||||||
|
if should_print_behavior then
|
||||||
|
IO.println (spec.name + ": [" + total_time.total_milliseconds.to_text + "ms]")
|
||||||
|
spec.behaviors.reverse.each behavior->
|
||||||
|
case behavior.result of
|
||||||
|
Test_Result.Success ->
|
||||||
|
if config.print_only_failures.not then
|
||||||
|
IO.println (" - " + behavior.name + " [" + behavior.time_taken.total_milliseconds.to_text + "ms]")
|
||||||
|
Test_Result.Failure msg details ->
|
||||||
|
IO.println (" - [FAILED] " + behavior.name + " [" + behavior.time_taken.total_milliseconds.to_text + "ms]")
|
||||||
|
IO.println (" Reason: " + msg)
|
||||||
|
if details.is_nothing.not then
|
||||||
|
IO.println details
|
||||||
|
Test_Result.Pending reason ->
|
||||||
|
if config.print_only_failures.not then
|
||||||
|
IO.println (" - [PENDING] " + behavior.name)
|
||||||
|
IO.println (" Reason: " + reason)
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
Record JUnit PENDING group.
|
||||||
|
report_pending_group : Text -> Text -> Suite_Config -> (StringBuilder|Nothing) -> Nothing
|
||||||
|
report_pending_group name reason config builder =
|
||||||
|
if config.should_output_junit then
|
||||||
|
builder.append (' <testsuite name="' + (escape_xml name) + '" timestamp="' + (Date_Time.now.format "yyyy-MM-dd'T'HH:mm:ss") + '" time="0">\n')
|
||||||
|
builder.append (' <testcase name="' + (escape_xml name) + '"><skipped message="' + (escape_xml reason) + '" /></testcase>\n')
|
||||||
|
builder.append ' </testsuite>\n'
|
||||||
|
|
||||||
|
IO.println ("[PENDING] " + name)
|
||||||
|
IO.println (" Reason: " + reason)
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
Escape Text for XML
|
||||||
|
escape_xml : Text -> Text
|
||||||
|
escape_xml input =
|
||||||
|
input.replace '&' '&' . replace '"' '"' . replace "'" ''' . replace '<' '<' . replace '>' '>'
|
@ -0,0 +1,24 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
|
||||||
|
type Test_Result
|
||||||
|
## Represents a successful behavioral test.
|
||||||
|
Success
|
||||||
|
|
||||||
|
## Represents a failing behavioral test.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- message: The reason why the test failed.
|
||||||
|
- details: Additional context of the error, for example the stack trace.
|
||||||
|
Failure message details
|
||||||
|
|
||||||
|
## Represents a pending behavioral test.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- reason: Text describing why the test is pending.
|
||||||
|
Pending reason
|
||||||
|
|
||||||
|
## Checks if the Test_Result is a failure.
|
||||||
|
is_fail : Boolean
|
||||||
|
is_fail self = case self of
|
||||||
|
Test_Result.Failure _ _ -> True
|
||||||
|
_ -> False
|
75
distribution/lib/Standard/Test/0.0.0-dev/src/Test_Suite.enso
Normal file
75
distribution/lib/Standard/Test/0.0.0-dev/src/Test_Suite.enso
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
from Standard.Base import all
|
||||||
|
import Standard.Base.Data.Time.Duration
|
||||||
|
import Standard.Base.Runtime.State
|
||||||
|
import Standard.Base.System
|
||||||
|
|
||||||
|
import project.Suite_Config.Suite_Config
|
||||||
|
import project.Test_Reporter
|
||||||
|
|
||||||
|
polyglot java import java.lang.StringBuilder
|
||||||
|
|
||||||
|
type Test_Suite
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
The top-level entry point for a test suite.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- config: Suite_Config controlloing the test run.
|
||||||
|
- specs: The specs contained within the test suite.
|
||||||
|
- builder: StringBuilder for JUnit output.
|
||||||
|
Value config specs builder
|
||||||
|
|
||||||
|
## Creates a new test group, describing properties of the object
|
||||||
|
described by `self`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- specs: An action encapsulating a number of test specs or groups.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Building a basic test suite.
|
||||||
|
|
||||||
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
|
example_run_main = Test_Suite.run_main <|
|
||||||
|
Test.group "Number" <|
|
||||||
|
Test.specify "should define addition" <|
|
||||||
|
2+3 . should_equal 5
|
||||||
|
Test.specify "should define multiplication" <|
|
||||||
|
2*3 . should_equal 6
|
||||||
|
run_main : Any -> Nothing
|
||||||
|
run_main ~specs =
|
||||||
|
config = Suite_Config.from_environment
|
||||||
|
r = Test_Suite.run specs config
|
||||||
|
code = if r.is_fail then 1 else 0
|
||||||
|
System.exit code
|
||||||
|
|
||||||
|
## Creates a new test group, describing properties of the object
|
||||||
|
described by `self`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- specs: An action encapsulating a number of test specs or groups.
|
||||||
|
|
||||||
|
> Example
|
||||||
|
Building a basic test suite.
|
||||||
|
|
||||||
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
|
example_run = Test_Suite.run <|
|
||||||
|
Test.group "Number" <|
|
||||||
|
Test.specify "should define addition" <|
|
||||||
|
2+3 . should_equal 5
|
||||||
|
Test.specify "should define multiplication" <|
|
||||||
|
2*3 . should_equal 6
|
||||||
|
run : Any -> Suite_Config -> Any
|
||||||
|
run ~specs config =
|
||||||
|
builder = if config.should_output_junit then StringBuilder.new else Nothing
|
||||||
|
Test_Reporter.wrap_junit_testsuites config builder <|
|
||||||
|
State.run Test_Suite (Test_Suite.Value config Nil builder) <|
|
||||||
|
specs
|
||||||
|
State.get Test_Suite
|
||||||
|
|
||||||
|
## PRIVATE
|
||||||
|
|
||||||
|
Checks if the suite contains any failures, and hence fails itself.
|
||||||
|
is_fail : Boolean
|
||||||
|
is_fail self = self.specs.any .is_fail
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base.Data.Time.Duration
|
import Standard.Base.Data.Time.Duration
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
polyglot java import org.graalvm.collections.Pair as Graal_Pair
|
polyglot java import org.graalvm.collections.Pair as Graal_Pair
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
prep_json size =
|
prep_json size =
|
||||||
single = '{"foo": 543}, {"bar": false}'
|
single = '{"foo": 543}, {"bar": false}'
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
import Standard.Base.Runtime.Debug
|
import Standard.Base.Runtime.Debug
|
||||||
import Standard.Base.Runtime.State
|
import Standard.Base.Runtime.State
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.lang.Long
|
polyglot java import java.lang.Long
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
## Bench Utilities ============================================================
|
## Bench Utilities ============================================================
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
## Bench Utilities ============================================================
|
## Bench Utilities ============================================================
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
from Standard.Base import IO, Integer, Vector, Statistics
|
from Standard.Base import IO, Integer, Vector, Statistics
|
||||||
from Standard.Base.Data.Statistics import all
|
from Standard.Base.Data.Statistics import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
## Bench Utilities ============================================================
|
## Bench Utilities ============================================================
|
||||||
|
|
||||||
|
@ -3,8 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Column_Selector
|
from Standard.Table import Table, Column_Selector
|
||||||
from Standard.Table.Data.Aggregate_Column import all
|
from Standard.Table.Data.Aggregate_Column import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
## Bench Utilities ============================================================
|
## Bench Utilities ============================================================
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import Standard.Base.Data.Time.Duration
|
|||||||
from Standard.Table import Table, Sort_Column_Selector
|
from Standard.Table import Table, Sort_Column_Selector
|
||||||
from Standard.Table.Data.Aggregate_Column import all
|
from Standard.Table.Data.Aggregate_Column import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
type My
|
type My
|
||||||
Data x
|
Data x
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base.Data.Text.Prim_Text_Helper
|
import Standard.Base.Data.Text.Prim_Text_Helper
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.lang.StringBuilder
|
polyglot java import java.lang.StringBuilder
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
compare_all_adjacent text_vector =
|
compare_all_adjacent text_vector =
|
||||||
res = 1.up_to text_vector.length . fold False acc-> ix->
|
res = 1.up_to text_vector.length . fold False acc-> ix->
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
check_all text_vector pattern_vector mode =
|
check_all text_vector pattern_vector mode =
|
||||||
text_vector.fold 0 acc-> text->
|
text_vector.fold 0 acc-> text->
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench, Faker
|
||||||
import Standard.Test.Faker
|
|
||||||
|
|
||||||
# Benchmarks ##################################################################
|
# Benchmarks ##################################################################
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
from Standard.Base.Data.Index_Sub_Range import Sample
|
from Standard.Base.Data.Index_Sub_Range import Sample
|
||||||
import Standard.Base.Data.Time.Duration
|
import Standard.Base.Data.Time.Duration
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base
|
import Standard.Base
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
polyglot java import org.enso.base.Time_Utils
|
polyglot java import org.enso.base.Time_Utils
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base.Runtime.Ref
|
import Standard.Base.Runtime.Ref
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
import project.Vector.Vector as Vector_Utils
|
import project.Vector.Vector as Vector_Utils
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Base
|
import Standard.Base
|
||||||
|
|
||||||
import Standard.Test.Bench
|
from Standard.Test import Bench
|
||||||
|
|
||||||
polyglot java import java.util.Random
|
polyglot java import java.util.Random
|
||||||
polyglot java import org.enso.base.Time_Utils
|
polyglot java import org.enso.base.Time_Utils
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
# While we're lacking the ability to run the documentation examples
|
# While we're lacking the ability to run the documentation examples
|
||||||
# automatically (#1706), these tests at least check that each of the examples
|
# automatically (#1706), these tests at least check that each of the examples
|
||||||
@ -10,8 +10,8 @@ import Standard.Test
|
|||||||
|
|
||||||
spec = Test.group "Examples" <|
|
spec = Test.group "Examples" <|
|
||||||
Test.specify "should allow construction of Example_Error_Type" <|
|
Test.specify "should allow construction of Example_Error_Type" <|
|
||||||
val = Examples.Example_Error_Type_Data "Oh, no! Something went wrong!"
|
val = Examples.Example_Error_Type.Error "Oh, no! Something went wrong!"
|
||||||
val.should_be_an Examples.Example_Error_Type_Data
|
val.should_be_an Examples.Example_Error_Type.Error
|
||||||
|
|
||||||
Test.specify "should allow getting the examples data directory" <|
|
Test.specify "should allow getting the examples data directory" <|
|
||||||
dir = Examples.data_dir
|
dir = Examples.data_dir
|
||||||
@ -58,13 +58,13 @@ spec = Test.group "Examples" <|
|
|||||||
Examples.no_such_method
|
Examples.no_such_method
|
||||||
|
|
||||||
Test.specify "should provide a dummy error type" <|
|
Test.specify "should provide a dummy error type" <|
|
||||||
Examples.My_Error_Data
|
Examples.My_Error.Error
|
||||||
|
|
||||||
Test.specify "should provide a method that throws an error" <|
|
Test.specify "should provide a method that throws an error" <|
|
||||||
Examples.throw_error.should_fail_with Examples.My_Error_Data
|
Examples.throw_error.should_fail_with Examples.My_Error.Error
|
||||||
|
|
||||||
Test.specify "should provide a method that throws a panic" <|
|
Test.specify "should provide a method that throws a panic" <|
|
||||||
Test.expect_panic_with Examples.throw_panic Examples.My_Error_Data
|
Test.expect_panic_with Examples.throw_panic Examples.My_Error.Error
|
||||||
|
|
||||||
Test.specify "should provide a URL for some geo data" <|
|
Test.specify "should provide a URL for some geo data" <|
|
||||||
(Examples.geo_data_url.length > 0) . should_be_true
|
(Examples.geo_data_url.length > 0) . should_be_true
|
||||||
@ -121,4 +121,4 @@ spec = Test.group "Examples" <|
|
|||||||
match.groups.length . should_equal 5
|
match.groups.length . should_equal 5
|
||||||
match.named_groups.size . should_equal 2
|
match.named_groups.size . should_equal 2
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.Examples_Spec
|
import project.Examples_Spec
|
||||||
|
|
||||||
main = Test.Suite.run_main <|
|
main = Test_Suite.run_main <|
|
||||||
Examples_Spec.spec
|
Examples_Spec.spec
|
||||||
|
@ -3,7 +3,7 @@ from Standard.Table.Data.Table.Table import Table_Data
|
|||||||
|
|
||||||
import Standard.Geo
|
import Standard.Geo
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "Geo Points" <|
|
Test.group "Geo Points" <|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.Geo_Spec
|
import project.Geo_Spec
|
||||||
|
|
||||||
main = Test.Suite.run_main <|
|
main = Test_Suite.run_main <|
|
||||||
Geo_Spec.spec
|
Geo_Spec.spec
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
import Standard.Google_Api
|
import Standard.Google_Api
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
main = Test.Suite.run_main <|
|
main = Test_Suite.run_main <|
|
||||||
secret = enso_project.data / 'secret.json'
|
secret = enso_project.data / 'secret.json'
|
||||||
api = Google_Api.initialize secret
|
api = Google_Api.initialize secret
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Data.Image
|
from Standard.Image import Image, Matrix
|
||||||
import Standard.Image.Data.Matrix
|
import Standard.Image.Data.Matrix_Error.Matrix_Error
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "Image with 1 channel" <|
|
Test.group "Image with 1 channel" <|
|
||||||
@ -30,8 +30,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1]
|
identity.get 0 0 . should_equal [1]
|
||||||
identity.get 1 0 . should_equal [0]
|
identity.get 1 0 . should_equal [0]
|
||||||
identity.get 1 1 . should_equal [1]
|
identity.get 1 1 . should_equal [1]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal ones
|
zeros+1 . should_equal ones
|
||||||
@ -50,7 +50,7 @@ spec =
|
|||||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal zeros
|
ones-1 . should_equal zeros
|
||||||
@ -67,7 +67,7 @@ spec =
|
|||||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal ones
|
ones*2 . should_equal ones
|
||||||
@ -85,7 +85,7 @@ spec =
|
|||||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -100,7 +100,7 @@ spec =
|
|||||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9 0.2) channels=1 rows=3)
|
(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" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Image with 2 channels" <|
|
Test.group "Image with 2 channels" <|
|
||||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x]) rows=3 channels=2
|
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x]) rows=3 channels=2
|
||||||
@ -125,8 +125,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0]
|
identity.get 0 0 . should_equal [1, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0]
|
identity.get 1 0 . should_equal [0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0]
|
identity.get 1 1 . should_equal [1, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal ones
|
zeros+1 . should_equal ones
|
||||||
@ -145,7 +145,7 @@ spec =
|
|||||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal zeros
|
ones-1 . should_equal zeros
|
||||||
@ -162,7 +162,7 @@ spec =
|
|||||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal ones
|
ones*2 . should_equal ones
|
||||||
@ -180,7 +180,7 @@ spec =
|
|||||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -195,7 +195,7 @@ spec =
|
|||||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*2 0.2) channels=2 rows=3)
|
(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" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Image with 3 channels" <|
|
Test.group "Image with 3 channels" <|
|
||||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x]) rows=3 channels=3
|
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x]) rows=3 channels=3
|
||||||
@ -221,8 +221,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0, 0]
|
identity.get 0 0 . should_equal [1, 0, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0, 0]
|
identity.get 1 0 . should_equal [0, 0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0, 0]
|
identity.get 1 1 . should_equal [1, 0, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal ones
|
zeros+1 . should_equal ones
|
||||||
@ -241,7 +241,7 @@ spec =
|
|||||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal zeros
|
ones-1 . should_equal zeros
|
||||||
@ -258,7 +258,7 @@ spec =
|
|||||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal ones
|
ones*2 . should_equal ones
|
||||||
@ -276,7 +276,7 @@ spec =
|
|||||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -291,7 +291,7 @@ spec =
|
|||||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*3 0.2) channels=3 rows=3)
|
(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" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Image with 4 channels" <|
|
Test.group "Image with 4 channels" <|
|
||||||
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x,x]) rows=3 channels=4
|
zeros = Image.from_vector (Vector.fill 9 0 . flat_map x->[x,x,x,x]) rows=3 channels=4
|
||||||
@ -317,8 +317,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal ones
|
zeros+1 . should_equal ones
|
||||||
@ -337,7 +337,7 @@ spec =
|
|||||||
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
(zeros + (zeros+0.8).to_matrix) . should_equal zeros+0.8
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal zeros
|
ones-1 . should_equal zeros
|
||||||
@ -354,7 +354,7 @@ spec =
|
|||||||
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
(ones - (zeros+0.8).to_matrix) . should_equal ones-0.8
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal ones
|
ones*2 . should_equal ones
|
||||||
@ -372,7 +372,7 @@ spec =
|
|||||||
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
(ones * (zeros-0.8).to_matrix) . should_equal zeros-0.8
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -387,4 +387,6 @@ spec =
|
|||||||
(ones / fives) . should_equal (Image.from_vector (Vector.fill 9*4 0.2) channels=4 rows=3)
|
(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" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Image.Data.Matrix
|
from Standard.Image import Matrix
|
||||||
|
import Standard.Image.Data.Matrix_Error.Matrix_Error
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "Matrix_Error" <|
|
Test.group "Matrix_Error" <|
|
||||||
Test.specify "should display errors" <|
|
Test.specify "should display errors" <|
|
||||||
(Matrix.Index_Out_Of_Bounds_Error 2 3 4).to_display_text . should_equal '''
|
(Matrix_Error.Index_Out_Of_Bounds_Error 2 3 4).to_display_text . should_equal '''
|
||||||
For a matrix with dimensions 2x3, the index 4 is out of bounds.
|
For a matrix with dimensions 2x3, the index 4 is out of bounds.
|
||||||
Matrix.Dimensions_Not_Equal.to_display_text . should_equal '''
|
Matrix_Error.Dimensions_Not_Equal.to_display_text . should_equal '''
|
||||||
Dimensions are not equal.
|
Dimensions are not equal.
|
||||||
Test.group "Matrix with 1 channel" <|
|
Test.group "Matrix with 1 channel" <|
|
||||||
zeros = Matrix.zeros 3 3
|
zeros = Matrix.zeros 3 3
|
||||||
@ -40,8 +41,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1]
|
identity.get 0 0 . should_equal [1]
|
||||||
identity.get 1 0 . should_equal [0]
|
identity.get 1 0 . should_equal [0]
|
||||||
identity.get 1 1 . should_equal [1]
|
identity.get 1 1 . should_equal [1]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal ones
|
zeros+1 . should_equal ones
|
||||||
@ -58,7 +59,7 @@ spec =
|
|||||||
ones+ones . should_equal twos
|
ones+ones . should_equal twos
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal zeros
|
ones-1 . should_equal zeros
|
||||||
@ -75,7 +76,7 @@ spec =
|
|||||||
identity-zeros . should_equal identity
|
identity-zeros . should_equal identity
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal twos
|
ones*2 . should_equal twos
|
||||||
@ -93,7 +94,7 @@ spec =
|
|||||||
identity*zeros . should_equal zeros
|
identity*zeros . should_equal zeros
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -108,7 +109,7 @@ spec =
|
|||||||
twos/twos . should_equal ones
|
twos/twos . should_equal ones
|
||||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Matrix with 2 channels" <|
|
Test.group "Matrix with 2 channels" <|
|
||||||
zeros = Matrix.zeros 3 3 channels=2
|
zeros = Matrix.zeros 3 3 channels=2
|
||||||
@ -138,8 +139,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0]
|
identity.get 0 0 . should_equal [1, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0]
|
identity.get 1 0 . should_equal [0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0]
|
identity.get 1 1 . should_equal [1, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*2 1) rows=3 channels=2)
|
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*2 1) rows=3 channels=2)
|
||||||
@ -157,7 +158,7 @@ spec =
|
|||||||
ones+ones . should_equal twos
|
ones+ones . should_equal twos
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=2)
|
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=2)
|
||||||
@ -174,7 +175,7 @@ spec =
|
|||||||
identity-zeros . should_equal identity
|
identity-zeros . should_equal identity
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal twos
|
ones*2 . should_equal twos
|
||||||
@ -192,7 +193,7 @@ spec =
|
|||||||
identity*zeros . should_equal zeros
|
identity*zeros . should_equal zeros
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -209,7 +210,7 @@ spec =
|
|||||||
twos/all_twos . should_equal ones
|
twos/all_twos . should_equal ones
|
||||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Matrix with 3 channels" <|
|
Test.group "Matrix with 3 channels" <|
|
||||||
zeros = Matrix.zeros 3 3 channels=3
|
zeros = Matrix.zeros 3 3 channels=3
|
||||||
@ -239,8 +240,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0, 0]
|
identity.get 0 0 . should_equal [1, 0, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0, 0]
|
identity.get 1 0 . should_equal [0, 0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0, 0]
|
identity.get 1 1 . should_equal [1, 0, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*3 1) rows=3 channels=3)
|
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*3 1) rows=3 channels=3)
|
||||||
@ -258,7 +259,7 @@ spec =
|
|||||||
ones+ones . should_equal twos
|
ones+ones . should_equal twos
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=3)
|
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=3)
|
||||||
@ -275,7 +276,7 @@ spec =
|
|||||||
identity-zeros . should_equal identity
|
identity-zeros . should_equal identity
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal twos
|
ones*2 . should_equal twos
|
||||||
@ -293,7 +294,7 @@ spec =
|
|||||||
identity*zeros . should_equal zeros
|
identity*zeros . should_equal zeros
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -310,7 +311,7 @@ spec =
|
|||||||
twos/all_twos . should_equal ones
|
twos/all_twos . should_equal ones
|
||||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.group "Matrix with 4 channels" <|
|
Test.group "Matrix with 4 channels" <|
|
||||||
zeros = Matrix.zeros 3 3 channels=4
|
zeros = Matrix.zeros 3 3 channels=4
|
||||||
@ -340,8 +341,8 @@ spec =
|
|||||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||||
identity.get 10 10 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
identity.get -1 -1 . should_fail_with Matrix.Index_Out_Of_Bounds_Error
|
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds_Error
|
||||||
|
|
||||||
Test.specify "should be able to add a scalar" <|
|
Test.specify "should be able to add a scalar" <|
|
||||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*4 1) rows=3 channels=4)
|
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*4 1) rows=3 channels=4)
|
||||||
@ -359,7 +360,7 @@ spec =
|
|||||||
ones+ones . should_equal twos
|
ones+ones . should_equal twos
|
||||||
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
Test.specify "should fail to add a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros+o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros+o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to subtract a scalar" <|
|
Test.specify "should be able to subtract a scalar" <|
|
||||||
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=4)
|
ones-1 . should_equal (Matrix.from_vector (ones.to_vector . map (_ - 1)) rows=3 channels=4)
|
||||||
@ -376,7 +377,7 @@ spec =
|
|||||||
identity-zeros . should_equal identity
|
identity-zeros . should_equal identity
|
||||||
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
Test.specify "should fail to subtract a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros-o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros-o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to multiply by a scalar" <|
|
Test.specify "should be able to multiply by a scalar" <|
|
||||||
ones*2 . should_equal twos
|
ones*2 . should_equal twos
|
||||||
@ -394,7 +395,7 @@ spec =
|
|||||||
identity*zeros . should_equal zeros
|
identity*zeros . should_equal zeros
|
||||||
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to multiply by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros*o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros*o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
Test.specify "should be able to divide by a scalar" <|
|
Test.specify "should be able to divide by a scalar" <|
|
||||||
zeros/2 . should_equal zeros
|
zeros/2 . should_equal zeros
|
||||||
@ -411,4 +412,6 @@ spec =
|
|||||||
twos/all_twos . should_equal ones
|
twos/all_twos . should_equal ones
|
||||||
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
Test.specify "should fail to divide by a matrix with mismatched dimensions" <|
|
||||||
o = Matrix.ones 2 3
|
o = Matrix.ones 2 3
|
||||||
zeros/o . should_fail_with Matrix.Dimensions_Not_Equal
|
zeros/o . should_fail_with Matrix_Error.Dimensions_Not_Equal
|
||||||
|
|
||||||
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,9 +3,9 @@ import Standard.Base.System.Platform
|
|||||||
import Standard.Base.System.Process
|
import Standard.Base.System.Process
|
||||||
import Standard.Base.System.Process.Exit_Code
|
import Standard.Base.System.Process.Exit_Code
|
||||||
|
|
||||||
import Standard.Image.Codecs
|
from Standard.Image import Image, Read_Flag, Write_Flag
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
polyglot java import java.lang.System as Java_System
|
polyglot java import java.lang.System as Java_System
|
||||||
|
|
||||||
@ -20,44 +20,46 @@ spec =
|
|||||||
True ->
|
True ->
|
||||||
case fetch rgba_addr rgba_file of
|
case fetch rgba_addr rgba_file of
|
||||||
Exit_Code.Exit_Failure _ ->
|
Exit_Code.Exit_Failure _ ->
|
||||||
"The Codecs spec was not able to fetch the file from " + rgba_addr
|
"The Image.Read spec was not able to fetch the file from " + rgba_addr
|
||||||
Exit_Code.Exit_Success ->
|
Exit_Code.Exit_Success ->
|
||||||
Nothing
|
Nothing
|
||||||
False ->
|
False ->
|
||||||
"The Codecs spec only run when the `CI` environment variable is set to true"
|
"The Image.Read spec only run when the `CI` environment variable is set to true"
|
||||||
|
|
||||||
Test.group "Codecs" pending=pending <|
|
Test.group "Image.read" pending=pending <|
|
||||||
Test.specify "should return error when read failed" <|
|
Test.specify "should return error when read failed" <|
|
||||||
Codecs.read (enso_project.root / 'no_such_file.png') . should_fail_with File.IO_Error
|
Image.read (enso_project.root / 'no_such_file.png') . should_fail_with File.IO_Error
|
||||||
Test.specify "should read a color image" <|
|
Test.specify "should read a color image" <|
|
||||||
img = Codecs.read rgba_file
|
img = Image.read rgba_file
|
||||||
img.rows.should_equal 160
|
img.rows.should_equal 160
|
||||||
img.columns.should_equal 320
|
img.columns.should_equal 320
|
||||||
img.channels.should_equal 3
|
img.channels.should_equal 3
|
||||||
Test.specify "should read an image as grayscale" <|
|
Test.specify "should read an image as grayscale" <|
|
||||||
img = Codecs.read rgba_file Codecs.Read_Grayscale
|
img = Image.read rgba_file Read_Flag.Grayscale
|
||||||
img.rows.should_equal 160
|
img.rows.should_equal 160
|
||||||
img.columns.should_equal 320
|
img.columns.should_equal 320
|
||||||
img.channels.should_equal 1
|
img.channels.should_equal 1
|
||||||
Test.specify "should read an image with an alpha channel" <|
|
Test.specify "should read an image with an alpha channel" <|
|
||||||
img = Codecs.read rgba_file Codecs.Read_Alpha_Channel
|
img = Image.read rgba_file Read_Flag.Alpha_Channel
|
||||||
img.rows.should_equal 160
|
img.rows.should_equal 160
|
||||||
img.columns.should_equal 320
|
img.columns.should_equal 320
|
||||||
img.channels.should_equal 4
|
img.channels.should_equal 4
|
||||||
|
|
||||||
Test.specify "should return error when write failed" <|
|
Test.specify "should return error when write failed" <|
|
||||||
out_file = enso_project.root / "no_such_directory" / "out.png"
|
out_file = enso_project.root / "no_such_directory" / "out.png"
|
||||||
Codecs.read rgba_file . write out_file . should_fail_with File.IO_Error
|
Image.read rgba_file . write out_file . should_fail_with File.IO_Error
|
||||||
Test.specify "should write a PNG file with alpha channel" <|
|
Test.specify "should write a PNG file with alpha channel" <|
|
||||||
out_file = enso_project.root / "out_alpha.png"
|
out_file = enso_project.root / "out_alpha.png"
|
||||||
Codecs.read rgba_file Codecs.Read_Alpha_Channel . write out_file
|
Image.read rgba_file Read_Flag.Alpha_Channel . write out_file
|
||||||
Test.specify "should write a grayscale PNG file" <|
|
Test.specify "should write a grayscale PNG file" <|
|
||||||
out_file = enso_project.root / "out_gray.png"
|
out_file = enso_project.root / "out_gray.png"
|
||||||
Codecs.read rgba_file Codecs.Read_Grayscale . write out_file
|
Image.read rgba_file Read_Flag.Grayscale . write out_file
|
||||||
Test.specify "should write a PNG file with compression" <|
|
Test.specify "should write a PNG file with compression" <|
|
||||||
out_file = enso_project.root / "out.png"
|
out_file = enso_project.root / "out.png"
|
||||||
Codecs.read rgba_file . write out_file (Codecs.Write_Png_Compression 3) . should_equal Nothing
|
Image.read rgba_file . write out_file (Write_Flag.PNG_Compression 3) . should_equal Nothing
|
||||||
Test.specify "should write a JPEG file with compression" <|
|
Test.specify "should write a JPEG file with compression" <|
|
||||||
out_file = enso_project.root / "out.jpeg"
|
out_file = enso_project.root / "out.jpeg"
|
||||||
flags = [Codecs.Write_Jpeg_Quality 75, Codecs.Write_Jpeg_Optimize, Codecs.Write_Jpeg_Progressive]
|
flags = [Write_Flag.JPEG_Quality 75, Write_Flag.JPEG_Optimize, Write_Flag.JPEG_Progressive]
|
||||||
Codecs.read rgba_file . write out_file flags . should_equal Nothing
|
Image.read rgba_file . write out_file flags . should_equal Nothing
|
||||||
|
|
||||||
|
main = Test_Suite.run_main spec
|
@ -1,12 +1,12 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.Codecs_Spec
|
import project.Image_Read_Spec
|
||||||
import project.Data.Image_Spec
|
import project.Data.Image_Spec
|
||||||
import project.Data.Matrix_Spec
|
import project.Data.Matrix_Spec
|
||||||
|
|
||||||
main = Test.Suite.run_main <|
|
main = Test_Suite.run_main <|
|
||||||
Codecs_Spec.spec
|
Image_Read_Spec.spec
|
||||||
Matrix_Spec.spec
|
Matrix_Spec.spec
|
||||||
Image_Spec.spec
|
Image_Spec.spec
|
||||||
|
@ -6,7 +6,7 @@ from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all
|
|||||||
import Standard.Table.Internal.Aggregate_Column_Helper
|
import Standard.Table.Internal.Aggregate_Column_Helper
|
||||||
import Standard.Table.Internal.Problem_Builder.Problem_Builder
|
import Standard.Table.Internal.Problem_Builder.Problem_Builder
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Aggregate Columns" <|
|
spec = Test.group "Aggregate Columns" <|
|
||||||
simple_table = Table.new [["count", [1, 2, Nothing, 3, Nothing]], ["is_valid", [Nothing, False, True, False, Nothing]], ["float", [3.4, 1, 5.6, 2.1, Nothing]], ["text", ["A", "", Nothing, "B,C", Nothing]]]
|
simple_table = Table.new [["count", [1, 2, Nothing, 3, Nothing]], ["is_valid", [Nothing, False, True, False, Nothing]], ["float", [3.4, 1, 5.6, 2.1, Nothing]], ["text", ["A", "", Nothing, "B,C", Nothing]]]
|
||||||
@ -196,4 +196,4 @@ spec = Test.group "Aggregate Columns" <|
|
|||||||
test_aggregator percentile_table (Percentile 0.66 0) "66%-ile tests" 70.78
|
test_aggregator percentile_table (Percentile 0.66 0) "66%-ile tests" 70.78
|
||||||
test_aggregator empty_table (Mode 0 test_name) test_name Nothing
|
test_aggregator empty_table (Mode 0 test_name) test_name Nothing
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -6,8 +6,7 @@ from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all
|
|||||||
from Standard.Table.Errors import Missing_Input_Columns_Data, Column_Indexes_Out_Of_Range_Data, No_Output_Columns, Duplicate_Output_Column_Names_Data, Invalid_Output_Column_Names_Data, Invalid_Aggregation_Data, Floating_Point_Grouping_Data, Unquoted_Delimiter_Data, Additional_Warnings_Data
|
from Standard.Table.Errors import Missing_Input_Columns_Data, Column_Indexes_Out_Of_Range_Data, No_Output_Columns, Duplicate_Output_Column_Names_Data, Invalid_Output_Column_Names_Data, Invalid_Aggregation_Data, Floating_Point_Grouping_Data, Unquoted_Delimiter_Data, Additional_Warnings_Data
|
||||||
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
polyglot java import java.lang.Double
|
polyglot java import java.lang.Double
|
||||||
|
|
||||||
@ -1389,4 +1388,4 @@ aggregate_spec prefix table empty_table table_builder materialize is_database te
|
|||||||
expect_sum_and_unsupported_errors 1 <|
|
expect_sum_and_unsupported_errors 1 <|
|
||||||
table.aggregate [Sum "X", Count_Distinct (By_Name ["X", "Y"])]
|
table.aggregate [Sum "X", Count_Distinct (By_Name ["X", "Y"])]
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -4,7 +4,7 @@ import Standard.Table.Data.Column.Empty_Error
|
|||||||
import Standard.Table.Data.Storage.Storage
|
import Standard.Table.Data.Storage.Storage
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
polyglot java import org.enso.table.data.column.storage.Storage as Java_Storage
|
polyglot java import org.enso.table.data.column.storage.Storage as Java_Storage
|
||||||
|
|
||||||
@ -98,4 +98,4 @@ spec = Test.group "Columns" <|
|
|||||||
sample.r_squared perfect_pred . should_equal 1
|
sample.r_squared perfect_pred . should_equal 1
|
||||||
sample.r_squared bad_pred . should_equal -3
|
sample.r_squared bad_pred . should_equal -3
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -10,8 +10,7 @@ from Standard.Table.Errors import all
|
|||||||
|
|
||||||
from Standard.Database.Errors import SQL_Error_Data
|
from Standard.Database.Errors import SQL_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
from Standard.Table import Table, Column, Delimited, Column_Selector
|
from Standard.Table import Table, Column, Delimited, Column_Selector
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
@ -108,4 +108,4 @@ spec =
|
|||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
|
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,8 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Column, Data_Formatter, Quote_Style
|
from Standard.Table import Table, Column, Data_Formatter, Quote_Style
|
||||||
from Standard.Table.Errors import all
|
from Standard.Table.Errors import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
type Custom_Type
|
type Custom_Type
|
||||||
Value field
|
Value field
|
||||||
@ -275,4 +274,4 @@ spec =
|
|||||||
formatter_3.true_values . should_equal []
|
formatter_3.true_values . should_equal []
|
||||||
formatter_3.false_values . should_equal []
|
formatter_3.false_values . should_equal []
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -10,8 +10,7 @@ import Standard.Database.Data.SQL_Type.SQL_Type
|
|||||||
from Standard.Database.Data.Table import combine_names, fresh_names
|
from Standard.Database.Data.Table import combine_names, fresh_names
|
||||||
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
import project.Database.Helpers.Fake_Test_Connection
|
import project.Database.Helpers.Fake_Test_Connection
|
||||||
|
|
||||||
@ -213,4 +212,4 @@ spec =
|
|||||||
code = t1.aggregate [Sum "A" "sum_a", Group_By "C" Nothing, Group_By "B" "B grp"] . to_sql . prepare
|
code = t1.aggregate [Sum "A" "sum_a", Group_By "C" Nothing, Group_By "B" "B grp"] . to_sql . prepare
|
||||||
code . should_equal ['SELECT SUM("T1"."A") AS "sum_a", "T1"."C" AS "C", "T1"."B" AS "B grp" FROM "T1" AS "T1" GROUP BY "T1"."C", "T1"."B"', []]
|
code . should_equal ['SELECT SUM("T1"."A") AS "sum_a", "T1"."C" AS "C", "T1"."B" AS "B grp" FROM "T1" AS "T1" GROUP BY "T1"."C", "T1"."B"', []]
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -7,8 +7,7 @@ from Standard.Table.Errors import No_Input_Columns_Selected, Missing_Input_Colum
|
|||||||
from Standard.Database import all
|
from Standard.Database import all
|
||||||
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
from Standard.Database.Errors import Unsupported_Database_Operation_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
import project.Database.Helpers.Name_Generator
|
import project.Database.Helpers.Name_Generator
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.Database.Codegen_Spec
|
import project.Database.Codegen_Spec
|
||||||
import project.Database.SQLite_Spec
|
import project.Database.SQLite_Spec
|
||||||
@ -13,4 +13,4 @@ databases_spec =
|
|||||||
Postgres_Spec.spec
|
Postgres_Spec.spec
|
||||||
Redshift_Spec.spec
|
Redshift_Spec.spec
|
||||||
|
|
||||||
main = Test.Suite.run_main databases_spec
|
main = Test_Suite.run_main databases_spec
|
||||||
|
@ -13,7 +13,7 @@ import Standard.Database.Data.SQL_Type.SQL_Type
|
|||||||
|
|
||||||
import Standard.Database.Internal.Postgres.Pgpass
|
import Standard.Database.Internal.Postgres.Pgpass
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
import Standard.Test.Test_Environment
|
import Standard.Test.Test_Environment
|
||||||
|
|
||||||
import project.Database.Common_Spec
|
import project.Database.Common_Spec
|
||||||
@ -360,4 +360,4 @@ spec =
|
|||||||
pgpass_spec
|
pgpass_spec
|
||||||
connection_setup_spec
|
connection_setup_spec
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -5,7 +5,7 @@ from Standard.Table import Table
|
|||||||
|
|
||||||
from Standard.Database import Database, Redshift, AWS_Credential, SQL_Query
|
from Standard.Database import Database, Redshift, AWS_Credential, SQL_Query
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
import project.Database.Common_Spec
|
import project.Database.Common_Spec
|
||||||
import project.Database.Helpers.Name_Generator
|
import project.Database.Helpers.Name_Generator
|
||||||
@ -122,4 +122,4 @@ spec =
|
|||||||
connection = Database.connect connection_details
|
connection = Database.connect connection_details
|
||||||
run_tests connection
|
run_tests connection
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -6,7 +6,7 @@ from Standard.Table import Table
|
|||||||
from Standard.Database import Database, SQLite, In_Memory, SQL_Query
|
from Standard.Database import Database, SQLite, In_Memory, SQL_Query
|
||||||
from Standard.Database.Errors import SQL_Error_Data
|
from Standard.Database.Errors import SQL_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
import project.Database.Common_Spec
|
import project.Database.Common_Spec
|
||||||
import project.Database.Helpers.Name_Generator
|
import project.Database.Helpers.Name_Generator
|
||||||
@ -137,4 +137,4 @@ spec =
|
|||||||
|
|
||||||
sqlite_spec (Database.connect (SQLite In_Memory)) "[SQLite Memory] "
|
sqlite_spec (Database.connect (SQLite In_Memory)) "[SQLite Memory] "
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,8 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Column, Data_Formatter, Quote_Style, Delimited
|
from Standard.Table import Table, Column, Data_Formatter, Quote_Style, Delimited
|
||||||
from Standard.Table.Errors import all
|
from Standard.Table.Errors import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
import project.Util
|
import project.Util
|
||||||
|
|
||||||
@ -393,4 +392,4 @@ spec =
|
|||||||
Delimited ',' comment_character='#' . without_comments . should_equal (Delimited ',' comment_character=Nothing)
|
Delimited ',' comment_character='#' . without_comments . should_equal (Delimited ',' comment_character=Nothing)
|
||||||
Delimited ',' . with_line_endings Line_Ending_Style.Unix . should_equal (Delimited ',' line_endings=Line_Ending_Style.Unix)
|
Delimited ',' . with_line_endings Line_Ending_Style.Unix . should_equal (Delimited ',' line_endings=Line_Ending_Style.Unix)
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -5,8 +5,7 @@ from Standard.Base.Error.Problem_Behavior import all
|
|||||||
from Standard.Table import Table, Column, Data_Formatter, Quote_Style, Column_Name_Mapping, Match_Columns, Delimited
|
from Standard.Table import Table, Column, Data_Formatter, Quote_Style, Column_Name_Mapping, Match_Columns, Delimited
|
||||||
from Standard.Table.Errors import all
|
from Standard.Table.Errors import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
@ -539,4 +538,4 @@ spec =
|
|||||||
result.catch.message . should_equal "The explicitly provided line endings ('\n') do not match the line endings in the file ('\r')."
|
result.catch.message . should_equal "The explicitly provided line endings ('\n') do not match the line endings in the file ('\r')."
|
||||||
file.delete
|
file.delete
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -7,8 +7,7 @@ from Standard.Table import Table, Match_Columns, Column_Name_Mapping, Excel, Exc
|
|||||||
|
|
||||||
from Standard.Table.Errors import Invalid_Output_Column_Names_Data, Duplicate_Output_Column_Names_Data, Invalid_Location_Data, Range_Exceeded_Data, Existing_Data_Data, Column_Count_Mismatch_Data, Column_Name_Mismatch_Data
|
from Standard.Table.Errors import Invalid_Output_Column_Names_Data, Duplicate_Output_Column_Names_Data, Invalid_Location_Data, Range_Exceeded_Data, Existing_Data_Data, Column_Count_Mismatch_Data, Column_Name_Mismatch_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
import Standard.Examples
|
import Standard.Examples
|
||||||
|
|
||||||
@ -630,4 +629,4 @@ spec =
|
|||||||
spec_write "xlsx" 'TestSheet.xlsx'
|
spec_write "xlsx" 'TestSheet.xlsx'
|
||||||
spec_write "xls" 'TestSheetOld.xls'
|
spec_write "xls" 'TestSheetOld.xls'
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,8 +2,7 @@ from Standard.Base import all
|
|||||||
from Standard.Base.System.File_Format import Unsupported_File_Type_Data
|
from Standard.Base.System.File_Format import Unsupported_File_Type_Data
|
||||||
|
|
||||||
import Standard.Table.IO.File_Read
|
import Standard.Table.IO.File_Read
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
sample_xxx = enso_project.data / "sample.xxx"
|
sample_xxx = enso_project.data / "sample.xxx"
|
||||||
@ -48,4 +47,4 @@ spec =
|
|||||||
problems = [Encoding_Error_Data "Encoding issues at 14, 15, 16."]
|
problems = [Encoding_Error_Data "Encoding issues at 14, 15, 16."]
|
||||||
Problems.test_problem_handling action problems tester
|
Problems.test_problem_handling action problems tester
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.Column_Spec
|
import project.Column_Spec
|
||||||
import project.Csv_Spec
|
import project.Csv_Spec
|
||||||
@ -25,4 +25,4 @@ in_memory_spec =
|
|||||||
Aggregate_Column_Spec.spec
|
Aggregate_Column_Spec.spec
|
||||||
Aggregate_Spec.spec
|
Aggregate_Spec.spec
|
||||||
|
|
||||||
main = Test.Suite.run_main in_memory_spec
|
main = Test_Suite.run_main in_memory_spec
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
from Standard.Table import Table
|
from Standard.Table import Table
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
import project.Util
|
import project.Util
|
||||||
|
|
||||||
@ -20,4 +20,4 @@ spec = Test.group 'JSON conversion' <|
|
|||||||
(Json.parse out.read_text).to_table ['a', 'b', 'c'] . should_equal simple_empty
|
(Json.parse out.read_text).to_table ['a', 'b', 'c'] . should_equal simple_empty
|
||||||
out.delete_if_exists
|
out.delete_if_exists
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test_Suite
|
||||||
|
|
||||||
import project.In_Memory_Tests
|
import project.In_Memory_Tests
|
||||||
import project.Database.Main as Database_Tests
|
import project.Database.Main as Database_Tests
|
||||||
import project.File_Read_Spec
|
import project.File_Read_Spec
|
||||||
import project.Data_Formatter_Spec
|
import project.Data_Formatter_Spec
|
||||||
|
|
||||||
main = Test.Suite.run_main <|
|
main = Test_Suite.run_main <|
|
||||||
In_Memory_Tests.in_memory_spec
|
In_Memory_Tests.in_memory_spec
|
||||||
Database_Tests.databases_spec
|
Database_Tests.databases_spec
|
||||||
File_Read_Spec.spec
|
File_Read_Spec.spec
|
||||||
|
@ -7,8 +7,7 @@ from Standard.Table.Errors import Invalid_Format, Leading_Zeros, Missing_Input_C
|
|||||||
|
|
||||||
import Standard.Visualization
|
import Standard.Visualization
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
|
|
||||||
spec = Test.group "Table.parse_values" <|
|
spec = Test.group "Table.parse_values" <|
|
||||||
Test.specify "should correctly parse integers" <|
|
Test.specify "should correctly parse integers" <|
|
||||||
@ -284,4 +283,4 @@ spec = Test.group "Table.parse_values" <|
|
|||||||
t2.at "floats" . to_vector . should_equal c2
|
t2.at "floats" . to_vector . should_equal c2
|
||||||
t2.at "bools" . to_vector . should_equal c3
|
t2.at "bools" . to_vector . should_equal c3
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,7 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Column, Delimited, Data_Formatter
|
from Standard.Table import Table, Column, Delimited, Data_Formatter
|
||||||
import Standard.Table.Data.Storage.Storage
|
import Standard.Table.Data.Storage.Storage
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
@ -49,4 +49,4 @@ spec =
|
|||||||
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
||||||
delimited.should_equal expected_text
|
delimited.should_equal expected_text
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -6,13 +6,12 @@ from Standard.Table import Table, Column, Sort_Column, Column_Selector, Sort_Col
|
|||||||
from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all hiding First, Last
|
from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all hiding First, Last
|
||||||
from Standard.Table.Data.Table import Empty_Error
|
from Standard.Table.Data.Table import Empty_Error
|
||||||
from Standard.Table.Data.Storage import Storage
|
from Standard.Table.Data.Storage import Storage
|
||||||
|
import Standard.Table.Data.Value_Type.Value_Type
|
||||||
from Standard.Table.Errors import Invalid_Output_Column_Names_Data, Duplicate_Output_Column_Names_Data, No_Input_Columns_Selected, Missing_Input_Columns_Data, No_Such_Column_Error_Data, Floating_Point_Grouping_Data, Invalid_Value_Type
|
from Standard.Table.Errors import Invalid_Output_Column_Names_Data, Duplicate_Output_Column_Names_Data, No_Input_Columns_Selected, Missing_Input_Columns_Data, No_Such_Column_Error_Data, Floating_Point_Grouping_Data, Invalid_Value_Type
|
||||||
|
|
||||||
import Standard.Visualization
|
import Standard.Visualization
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite, Problems
|
||||||
import Standard.Test.Problems
|
|
||||||
import Standard.Table.Data.Value_Type.Value_Type
|
|
||||||
|
|
||||||
import project.Common_Table_Spec
|
import project.Common_Table_Spec
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
@ -1028,7 +1027,7 @@ spec =
|
|||||||
check_timing "dates" <|
|
check_timing "dates" <|
|
||||||
t.filter date_col (Filter_Condition.Is_In dates_vec) . at "X" . to_vector . should_equal expected_vector
|
t.filter date_col (Filter_Condition.Is_In dates_vec) . at "X" . to_vector . should_equal expected_vector
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
|
||||||
## JS indexes months form 0, so we need to subtract 1.
|
## JS indexes months form 0, so we need to subtract 1.
|
||||||
foreign js js_make_date year month day = """
|
foreign js js_make_date year month day = """
|
||||||
|
@ -3,7 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Delimited, Column, Data_Formatter
|
from Standard.Table import Table, Delimited, Column, Data_Formatter
|
||||||
import Standard.Table.Data.Storage
|
import Standard.Table.Data.Storage
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
@ -47,4 +47,4 @@ spec =
|
|||||||
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
||||||
delimited.should_equal expected_text
|
delimited.should_equal expected_text
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,7 +3,7 @@ from Standard.Base import all
|
|||||||
from Standard.Table import Table, Delimited, Column, Data_Formatter
|
from Standard.Table import Table, Delimited, Column, Data_Formatter
|
||||||
import Standard.Table.Data.Storage
|
import Standard.Table.Data.Storage
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
from project.Util import all
|
from project.Util import all
|
||||||
|
|
||||||
@ -46,4 +46,4 @@ spec =
|
|||||||
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
delimited = Text.from test_table format=(Delimited "," value_formatter=data_formatter line_endings=Line_Ending_Style.Unix)
|
||||||
delimited.should_equal expected_text
|
delimited.should_equal expected_text
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
import Standard.Table.Internal.Unique_Name_Strategy.Unique_Name_Strategy
|
import Standard.Table.Internal.Unique_Name_Strategy.Unique_Name_Strategy
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group 'Unique_Name_Strategy Helper' <|
|
spec = Test.group 'Unique_Name_Strategy Helper' <|
|
||||||
Test.specify 'should change an empty name to "Column"' <|
|
Test.specify 'should change an empty name to "Column"' <|
|
||||||
@ -40,4 +40,4 @@ spec = Test.group 'Unique_Name_Strategy Helper' <|
|
|||||||
strategy.renames.length . should_equal 2
|
strategy.renames.length . should_equal 2
|
||||||
strategy.invalid_names.length . should_equal 0
|
strategy.invalid_names.length . should_equal 0
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,7 +3,7 @@ import Standard.Base.System
|
|||||||
|
|
||||||
from Standard.Table import Table, Column
|
from Standard.Table import Table, Column
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test
|
||||||
|
|
||||||
Table.should_equal self expected =
|
Table.should_equal self expected =
|
||||||
self_cols = self.columns
|
self_cols = self.columns
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "JavaScript Objects, Arrays & Functions" <|
|
Test.group "JavaScript Objects, Arrays & Functions" <|
|
||||||
@ -61,7 +61,7 @@ spec =
|
|||||||
(enso_vector.at 2).should_equal Nothing
|
(enso_vector.at 2).should_equal Nothing
|
||||||
enso_vector.should_equal js_arr
|
enso_vector.should_equal js_arr
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
|
||||||
foreign js data = """
|
foreign js data = """
|
||||||
var object = { name : "java.lang.Object", superclass: null };
|
var object = { name : "java.lang.Object", superclass: null };
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
polyglot java import java.util.LinkedHashSet
|
polyglot java import java.util.LinkedHashSet
|
||||||
|
|
||||||
@ -62,4 +62,4 @@ spec =
|
|||||||
as_vec = json.into (Vector.fill 1 Number)
|
as_vec = json.into (Vector.fill 1 Number)
|
||||||
as_vec.should_equal <| Vector.fill 100 0
|
as_vec.should_equal <| Vector.fill 100 0
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
Boolean.method self = self
|
Boolean.method self = self
|
||||||
|
|
||||||
@ -41,4 +41,4 @@ spec =
|
|||||||
(1 == 0) && "foo" . should_equal False
|
(1 == 0) && "foo" . should_equal False
|
||||||
(1 == 1) && "foo" . should_equal "foo"
|
(1 == 1) && "foo" . should_equal "foo"
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "identity" <|
|
Test.group "identity" <|
|
||||||
@ -37,4 +37,4 @@ spec =
|
|||||||
times = uncurry (*)
|
times = uncurry (*)
|
||||||
times [6, 7] . should_equal 42
|
times [6, 7] . should_equal 42
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "Bound" <|
|
Test.group "Bound" <|
|
||||||
@ -101,4 +101,4 @@ spec =
|
|||||||
Interval.inclusive 0 0 . not_empty . should_be_true
|
Interval.inclusive 0 0 . not_empty . should_be_true
|
||||||
Interval.inclusive 10 0 . not_empty . should_be_false
|
Interval.inclusive 10 0 . not_empty . should_be_false
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
import Standard.Test.Test_Result.Test_Result
|
||||||
|
|
||||||
type Author
|
type Author
|
||||||
Value name year_of_birth
|
Value name year_of_birth
|
||||||
@ -10,24 +11,24 @@ type Book
|
|||||||
|
|
||||||
Text.should_fail_parsing_with self expected =
|
Text.should_fail_parsing_with self expected =
|
||||||
as_fail = case Json.parse self of
|
as_fail = case Json.parse self of
|
||||||
_ -> Test.Failure "Expected a parse error, but no error reported."
|
_ -> Test_Result.Failure "Expected a parse error, but no error reported."
|
||||||
result = as_fail.catch Any e-> case e of
|
result = as_fail.catch Any e-> case e of
|
||||||
Json.Parse_Error_Data msg ->
|
Json.Parse_Error_Data msg ->
|
||||||
if msg.contains expected then Test.Success else
|
if msg.contains expected then Test_Result.Success else
|
||||||
fail_msg = "The reported message " + msg.to_text + " did not contain " + expected.to_text + "."
|
fail_msg = "The reported message " + msg.to_text + " did not contain " + expected.to_text + "."
|
||||||
Test.Failure fail_msg
|
Test_Result.Failure fail_msg
|
||||||
_ ->
|
_ ->
|
||||||
fail_msg = "Expected a parser error, but " + e.to_text + " was thrown."
|
fail_msg = "Expected a parser error, but " + e.to_text + " was thrown."
|
||||||
Test.Failure fail_msg
|
Test_Result.Failure fail_msg
|
||||||
case result of
|
case result of
|
||||||
Test.Success -> Test.Success
|
Test_Result.Success -> Test_Result.Success
|
||||||
fail -> Panic.throw fail
|
_ -> Panic.throw result
|
||||||
|
|
||||||
Text.should_parse_as self expected =
|
Text.should_parse_as self expected =
|
||||||
Test.Verbs.equal (Json.parse self) expected.to_json
|
Json.parse self . should_equal expected.to_json
|
||||||
|
|
||||||
Text.should_render_itself self =
|
Text.should_render_itself self =
|
||||||
Test.Verbs.equal (Json.parse self . to_text) self
|
Json.parse self . to_text . should_equal self
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "JSON Deserialization" <|
|
Test.group "JSON Deserialization" <|
|
||||||
@ -125,4 +126,4 @@ spec =
|
|||||||
object.get "foo" . should_equal (Json.String "bar")
|
object.get "foo" . should_equal (Json.String "bar")
|
||||||
object.get "bar" . should_fail_with Json.No_Such_Field_Error_Data
|
object.get "bar" . should_fail_with Json.No_Such_Field_Error_Data
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
from Standard.Base.Data.List import Empty_Error
|
from Standard.Base.Data.List import Empty_Error
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "List" <|
|
spec = Test.group "List" <|
|
||||||
l = Cons 1 <| Cons 2 <| Cons 3 <| Nil
|
l = Cons 1 <| Cons 2 <| Cons 3 <| Nil
|
||||||
@ -122,4 +122,4 @@ spec = Test.group "List" <|
|
|||||||
l.rest . should_equal (Cons 2 (Cons 3 Nil))
|
l.rest . should_equal (Cons 2 (Cons 3 Nil))
|
||||||
empty.rest.should_fail_with Empty_Error
|
empty.rest.should_fail_with Empty_Error
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
polyglot java import java.util.Locale as JavaLocale
|
polyglot java import java.util.Locale as JavaLocale
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
with_locale locale ~test =
|
with_locale locale ~test =
|
||||||
default_locale = JavaLocale.getDefault
|
default_locale = JavaLocale.getDefault
|
||||||
@ -74,4 +74,4 @@ spec = Test.group "Locale" <|
|
|||||||
Locale.uk . should_equal Locale.uk
|
Locale.uk . should_equal Locale.uk
|
||||||
Locale.uk . should_not_equal Locale.us
|
Locale.uk . should_not_equal Locale.us
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
from Standard.Base.Data.Map import No_Value_For_Key_Error_Data
|
from Standard.Base.Data.Map import No_Value_For_Key_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Maps" <|
|
spec = Test.group "Maps" <|
|
||||||
m = Map.empty . insert 1 2 . insert 2 4
|
m = Map.empty . insert 1 2 . insert 2 4
|
||||||
@ -108,4 +108,4 @@ spec = Test.group "Maps" <|
|
|||||||
m = Map.empty
|
m = Map.empty
|
||||||
m.last . should_equal Nothing
|
m.last . should_equal Nothing
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Maybe" <|
|
spec = Test.group "Maybe" <|
|
||||||
Test.specify "should have a None variant" <|
|
Test.specify "should have a None variant" <|
|
||||||
@ -17,3 +17,4 @@ spec = Test.group "Maybe" <|
|
|||||||
Maybe.None.is_none . should_be_true
|
Maybe.None.is_none . should_be_true
|
||||||
Maybe.Some 2 . is_none . should_be_false
|
Maybe.Some 2 . is_none . should_be_false
|
||||||
|
|
||||||
|
main = Test_Suite.run_main spec
|
||||||
|
@ -3,7 +3,7 @@ from Standard.Base import all
|
|||||||
import Standard.Base.Data.Noise.Generator
|
import Standard.Base.Data.Noise.Generator
|
||||||
import Standard.Base.Error.Common
|
import Standard.Base.Error.Common
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
Test.group "Generator Interface" <|
|
Test.group "Generator Interface" <|
|
||||||
@ -22,4 +22,4 @@ spec =
|
|||||||
values = 1.up_to 10000 . to_vector . map (gen.step _ interval)
|
values = 1.up_to 10000 . to_vector . map (gen.step _ interval)
|
||||||
values.all (v -> (v >= -100) && (v <= 100)) . should_be_true
|
values.all (v -> (v >= -100) && (v <= 100)) . should_be_true
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
type My_Generator
|
type My_Generator
|
||||||
My_Generator.step self _ _ = 1
|
My_Generator.step self _ _ = 1
|
||||||
@ -17,3 +17,4 @@ spec = Test.group "Noise" <|
|
|||||||
values = 1.up_to 10001 . to_vector . map (_.noise interval)
|
values = 1.up_to 10001 . to_vector . map (_.noise interval)
|
||||||
values.all (v -> (v >= -250) && (v <= 250)) . should_be_true
|
values.all (v -> (v >= -250) && (v <= 250)) . should_be_true
|
||||||
|
|
||||||
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
from Standard.Base.Data.Numbers import Parse_Error_Data
|
from Standard.Base.Data.Numbers import Parse_Error_Data
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
Integer.is_even self = self % 2 == 0
|
Integer.is_even self = self % 2 == 0
|
||||||
|
|
||||||
@ -320,4 +320,4 @@ spec =
|
|||||||
Number.nan . equals Number.nan . should_be_false
|
Number.nan . equals Number.nan . should_be_false
|
||||||
Number.nan . equals 0 . should_be_false
|
Number.nan . equals 0 . should_be_false
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -4,15 +4,15 @@ import Standard.Base.Data.Ordering.Comparator
|
|||||||
|
|
||||||
polyglot java import java.lang.ClassCastException
|
polyglot java import java.lang.ClassCastException
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
# === Test Resources ===
|
# === Test Resources ===
|
||||||
|
|
||||||
type Ord
|
type Ord
|
||||||
Value number
|
Value number
|
||||||
|
|
||||||
Ord.compare_to : Ord -> Ordering
|
compare_to : Ord -> Ordering
|
||||||
Ord.compare_to self that = that.number.compare_to self.number
|
compare_to self that = that.number.compare_to self.number
|
||||||
|
|
||||||
type No_Ord
|
type No_Ord
|
||||||
Value number
|
Value number
|
||||||
@ -61,4 +61,4 @@ spec = Test.group "Object Comparator" <|
|
|||||||
(default_comparator 1 True).should_fail_with Incomparable_Values_Error
|
(default_comparator 1 True).should_fail_with Incomparable_Values_Error
|
||||||
(default_comparator (No_Ord.Value 1) (No_Ord.Value 2)).should_fail_with Incomparable_Values_Error
|
(default_comparator (No_Ord.Value 1) (No_Ord.Value 2)).should_fail_with Incomparable_Values_Error
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Natural Order" <|
|
spec = Test.group "Natural Order" <|
|
||||||
case_insensitive_compare a b = Natural_Order.compare a b Case_Sensitivity.Insensitive
|
case_insensitive_compare a b = Natural_Order.compare a b Case_Sensitivity.Insensitive
|
||||||
@ -58,4 +58,4 @@ spec = Test.group "Natural Order" <|
|
|||||||
|
|
||||||
["1.0002", "1.0001", "1.01", "1.1", "1.10", "1.2", "2", "0", "1.20"].sort by=Natural_Order.compare . should_equal ["0", "1.0001", "1.01", "1.1", "1.0002", "1.2", "1.10", "1.20", "2"]
|
["1.0002", "1.0001", "1.01", "1.1", "1.10", "1.2", "2", "0", "1.20"].sort by=Natural_Order.compare . should_equal ["0", "1.0001", "1.01", "1.1", "1.0002", "1.2", "1.10", "1.20", "2"]
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
import Standard.Base.Data.Ordering.Vector_Lexicographic_Order
|
import Standard.Base.Data.Ordering.Vector_Lexicographic_Order
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
type My_Type
|
type My_Type
|
||||||
Value a b
|
Value a b
|
||||||
@ -19,4 +19,4 @@ spec = Test.group "Lexicographic Order on Vectors" <|
|
|||||||
Vector_Lexicographic_Order.compare [My_Type.Value "a" 1, My_Type.Value "b" 1, My_Type.Value "c" 1] [My_Type.Value "b" 1, My_Type.Value "a" 1, My_Type.Value "c" 1] element_comparator=comparator . should_equal Ordering.Less
|
Vector_Lexicographic_Order.compare [My_Type.Value "a" 1, My_Type.Value "b" 1, My_Type.Value "c" 1] [My_Type.Value "b" 1, My_Type.Value "a" 1, My_Type.Value "c" 1] element_comparator=comparator . should_equal Ordering.Less
|
||||||
Vector_Lexicographic_Order.compare [My_Type.Value "a" 1, My_Type.Value "b" 1, My_Type.Value "c" 1] [My_Type.Value "a" 100, My_Type.Value "b" 2, My_Type.Value "c" 3] element_comparator=comparator . should_equal Ordering.Equal
|
Vector_Lexicographic_Order.compare [My_Type.Value "a" 1, My_Type.Value "b" 1, My_Type.Value "c" 1] [My_Type.Value "a" 100, My_Type.Value "b" 2, My_Type.Value "c" 3] element_comparator=comparator . should_equal Ordering.Equal
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
from Standard.Base import all
|
from Standard.Base import all
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
# === Test Resources ===
|
# === Test Resources ===
|
||||||
|
|
||||||
type Ord
|
type Ord
|
||||||
Value number
|
Value number
|
||||||
|
|
||||||
Ord.compare_to : Ord -> Ordering
|
compare_to : Ord -> Ordering
|
||||||
Ord.compare_to self that = if self.number == that.number then Ordering.Equal else
|
compare_to self that = if self.number == that.number then Ordering.Equal else
|
||||||
if self.number > that.number then Ordering.Greater else Ordering.Less
|
if self.number > that.number then Ordering.Greater else Ordering.Less
|
||||||
|
|
||||||
|
|
||||||
# === The Tests ===
|
# === The Tests ===
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
@ -42,4 +41,4 @@ spec =
|
|||||||
Ordering.from_sign 0 . should_equal Ordering.Equal
|
Ordering.from_sign 0 . should_equal Ordering.Equal
|
||||||
Ordering.from_sign 1 . should_equal Ordering.Greater
|
Ordering.from_sign 1 . should_equal Ordering.Greater
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
import Standard.Base.Runtime.Ref
|
import Standard.Base.Runtime.Ref
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Range" <|
|
spec = Test.group "Range" <|
|
||||||
Test.specify "should be created with a start, an end and a step" <|
|
Test.specify "should be created with a start, an end and a step" <|
|
||||||
@ -380,4 +380,4 @@ spec = Test.group "Range" <|
|
|||||||
invalid_range . find _->True . should_fail_with Illegal_State_Error_Data
|
invalid_range . find _->True . should_fail_with Illegal_State_Error_Data
|
||||||
invalid_range . contains 0 . should_fail_with Illegal_State_Error_Data
|
invalid_range . contains 0 . should_fail_with Illegal_State_Error_Data
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -2,7 +2,7 @@ from Standard.Base import all
|
|||||||
|
|
||||||
import Standard.Base.Runtime.Ref
|
import Standard.Base.Runtime.Ref
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec = Test.group "Refs" <|
|
spec = Test.group "Refs" <|
|
||||||
Test.specify "should be able to store and retrieve value in references" <|
|
Test.specify "should be able to store and retrieve value in references" <|
|
||||||
@ -11,4 +11,4 @@ spec = Test.group "Refs" <|
|
|||||||
v = r.get
|
v = r.get
|
||||||
v.should_equal 'bar'
|
v.should_equal 'bar'
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from Standard.Base import Nothing, Vector, Number, Decimal, True, Illegal_Argument_Error_Data, False, Regression
|
from Standard.Base import Nothing, Vector, Number, Decimal, True, Illegal_Argument_Error_Data, False, Regression
|
||||||
|
|
||||||
import Standard.Test
|
from Standard.Test import Test, Test_Suite
|
||||||
|
|
||||||
spec =
|
spec =
|
||||||
## Regression test data produced using an Excel spreadsheet.
|
## Regression test data produced using an Excel spreadsheet.
|
||||||
@ -105,4 +105,4 @@ spec =
|
|||||||
expected_ys = [0.222594, 0.302868, 0.3046, 0.309085]
|
expected_ys = [0.222594, 0.302868, 0.3046, 0.309085]
|
||||||
vector_compare (test_xs.map fitted.predict) expected_ys
|
vector_compare (test_xs.map fitted.predict) expected_ys
|
||||||
|
|
||||||
main = Test.Suite.run_main spec
|
main = Test_Suite.run_main spec
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user