mirror of
https://github.com/enso-org/enso.git
synced 2025-01-03 11:11:50 +03:00
Stop publishing First
/Last
as constructors and use auto-scoping for take
and drop
. (#10467)
- Removes `First` and `Last` from the `Standard.Base` exports. - Enable auto-scoping for all `Index_Sub_Range` and `Text_Sub_Range`. - Update all use of those methods to use auto-scoping.
This commit is contained in:
parent
53eec66eda
commit
4c0647ea29
@ -13,10 +13,12 @@
|
||||
- [Renamed `Location.Start` to `Location.Left` and `Location.End` to
|
||||
`Location.Right`.][10445]
|
||||
- [Renamed `Postgres_Details.Postgres` to `Postgres.Server`.][10466]
|
||||
- [Remove `First` and `Last` from namespace, use auto-scoped.][10467]
|
||||
|
||||
[10434]: https://github.com/enso-org/enso/pull/10434
|
||||
[10445]: https://github.com/enso-org/enso/pull/10445
|
||||
[10466]: https://github.com/enso-org/enso/pull/10466
|
||||
[10467]: https://github.com/enso-org/enso/pull/10467
|
||||
|
||||
# Enso 2024.2
|
||||
|
||||
|
@ -75,9 +75,9 @@ type S3_Path
|
||||
without the trailing delimiter.
|
||||
file_name self -> Text =
|
||||
if self.is_root then S3_Path.delimiter else
|
||||
trimmed = if self.key.ends_with S3_Path.delimiter then self.key.drop (Last 1) else self.key
|
||||
trimmed = if self.key.ends_with S3_Path.delimiter then self.key.drop (..Last 1) else self.key
|
||||
last_index = trimmed.last_index_of S3_Path.delimiter
|
||||
if last_index == Nothing then trimmed else trimmed.drop (First last_index+1)
|
||||
if last_index == Nothing then trimmed else trimmed.drop (..First last_index+1)
|
||||
|
||||
## PRIVATE
|
||||
Checks if the given other path is inside of this path.
|
||||
@ -126,7 +126,7 @@ type Decomposed_S3_Path
|
||||
True -> parts.map Path_Entry.Directory
|
||||
False ->
|
||||
if parts.is_empty then [] else
|
||||
(parts.drop (Last 1) . map Path_Entry.Directory) + [Path_Entry.File parts.last]
|
||||
(parts.drop (..Last 1) . map Path_Entry.Directory) + [Path_Entry.File parts.last]
|
||||
Decomposed_S3_Path.Value entries has_root_prefix
|
||||
|
||||
## PRIVATE
|
||||
@ -152,5 +152,5 @@ type Decomposed_S3_Path
|
||||
## PRIVATE
|
||||
parent self -> Decomposed_S3_Path | Nothing =
|
||||
if self.parts.is_empty then Nothing else
|
||||
new_parts = self.parts.drop (Last 1)
|
||||
new_parts = self.parts.drop (..Last 1)
|
||||
Decomposed_S3_Path.Value new_parts self.go_to_root
|
||||
|
@ -162,7 +162,7 @@ type Array
|
||||
If a `Range`, the selection is specified by two indices, from and to.
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Vector Any
|
||||
take self range=(Index_Sub_Range.First 1) =
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Array_Like_Helpers.take self range
|
||||
|
||||
## ALIAS skip, remove
|
||||
@ -177,7 +177,7 @@ type Array
|
||||
If a `Range`, the selection is specified by two indices, from and to.
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Vector Any
|
||||
drop self range=(Index_Sub_Range.First 1) =
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Array_Like_Helpers.drop self range
|
||||
|
||||
## GROUP Calculations
|
||||
|
@ -81,12 +81,12 @@ type Index_Sub_Range
|
||||
`Range` too.
|
||||
default_options : Vector Option
|
||||
default_options =
|
||||
o1 = Option "First" "(Index_Sub_Range.First 1)"
|
||||
o2 = Option "Last" "(Index_Sub_Range.Last 1)"
|
||||
o3 = Option "While" "(Index_Sub_Range.While (x-> False))"
|
||||
o4 = Option "By_Index" "(Index_Sub_Range.By_Index [0])"
|
||||
o5 = Option "Sample" "(Index_Sub_Range.Sample 10)"
|
||||
o6 = Option "Every" "(Index_Sub_Range.Every 2)"
|
||||
o1 = Option "First" "(..First 1)"
|
||||
o2 = Option "Last" "(..Last 1)"
|
||||
o3 = Option "While" "(..While (x-> False))"
|
||||
o4 = Option "By_Index" "(..By_Index [0])"
|
||||
o5 = Option "Sample" "(..Sample 10)"
|
||||
o6 = Option "Every" "(..Every 2)"
|
||||
o7 = Option "Range" "(Range.new 0 100)"
|
||||
[o1, o2, o3, o4, o5, o6, o7]
|
||||
|
||||
@ -196,7 +196,7 @@ sort_and_merge_ranges ranges =
|
||||
normalization on its own.
|
||||
- range: The `Index_Sub_Range` to take from the collection.
|
||||
take_helper : Integer -> (Integer -> Any) -> (Integer -> Integer -> Any) -> (Vector (Integer | Range) -> Vector Any) -> (Index_Sub_Range | Range | Integer) -> Any
|
||||
take_helper length at single_slice slice_ranges range = case range of
|
||||
take_helper length at single_slice slice_ranges range:(Index_Sub_Range | Range | Integer) = case range of
|
||||
count : Integer -> take_helper length at single_slice slice_ranges (Index_Sub_Range.First count)
|
||||
_ : Range -> take_helper length at single_slice slice_ranges (Index_Sub_Range.By_Index range)
|
||||
Index_Sub_Range.First count -> single_slice 0 (length.min count)
|
||||
@ -247,7 +247,7 @@ take_helper length at single_slice slice_ranges range = case range of
|
||||
normalized.
|
||||
- range: The `Index_Sub_Range` to drop from the collection.
|
||||
drop_helper : Integer -> (Integer -> Any) -> (Integer -> Integer -> Any) -> (Vector (Integer | Range) -> Vector Any) -> (Index_Sub_Range | Range | Integer) -> Any
|
||||
drop_helper length at single_slice slice_ranges range = case range of
|
||||
drop_helper length at single_slice slice_ranges range:(Index_Sub_Range | Range | Integer) = case range of
|
||||
_ : Integer -> single_slice range length
|
||||
_ : Range -> drop_helper length at single_slice slice_ranges (Index_Sub_Range.By_Index range)
|
||||
Index_Sub_Range.First count -> single_slice count length
|
||||
|
@ -11,7 +11,6 @@ import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Data.Numeric.Math_Context.Math_Context
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Deprecated.Deprecated
|
||||
|
@ -1033,29 +1033,29 @@ Text.repeat self count=1 =
|
||||
> Example
|
||||
Various different ways to take part of "Hello World!"
|
||||
|
||||
"Hello World!".take First == "H"
|
||||
"Hello World!".take (First 5) == "Hello"
|
||||
"Hello World!".take (First 0) == ""
|
||||
"Hello World!".take Last == "!"
|
||||
"Hello World!".take (Last 6) == "World!"
|
||||
"Hello World!".take (Before " ") == "Hello"
|
||||
"Hello World!".take (Before_Last "o") == "Hello W"
|
||||
"Hello World!".take (After " ") == "World!"
|
||||
"Hello World!".take (After_Last "o") == "rld!"
|
||||
"Hello World!".take (While c->c!=" ") == "Hello"
|
||||
"Hello World!".take (Range 3 5) == "lo"
|
||||
"Hello World!".take (Range 5 Nothing) == " World!"
|
||||
"Hello World!".take (Range 5 12) == " World!"
|
||||
"Hello World!".take (Range 6 12 2) == "Wrd"
|
||||
"Hello World!".take (Every 2 first=6) == "Wrd"
|
||||
"Hello World!".take (Every 3) == "Hl Wl"
|
||||
"Hello World!".take (By_Index 0) == "H"
|
||||
"Hello World!".take (By_Index [1, 0, 0, 6, 0]) == "eHHWH"
|
||||
"Hello World!".take (By_Index [Range 0 3, 6, Range 6 12 2]) == "HelWWrd"
|
||||
"Hello World!".take (Sample 3 seed=42) == "l d"
|
||||
"Hello World!".take ..First == "H"
|
||||
"Hello World!".take (..First 5) == "Hello"
|
||||
"Hello World!".take (..First 0) == ""
|
||||
"Hello World!".take ..Last == "!"
|
||||
"Hello World!".take (..Last 6) == "World!"
|
||||
"Hello World!".take (..Before " ") == "Hello"
|
||||
"Hello World!".take (..Before_Last "o") == "Hello W"
|
||||
"Hello World!".take (..After " ") == "World!"
|
||||
"Hello World!".take (..After_Last "o") == "rld!"
|
||||
"Hello World!".take (..While c->c!=" ") == "Hello"
|
||||
"Hello World!".take (..Range 3 5) == "lo"
|
||||
"Hello World!".take (..Range 5 Nothing) == " World!"
|
||||
"Hello World!".take (..Range 5 12) == " World!"
|
||||
"Hello World!".take (..Range 6 12 2) == "Wrd"
|
||||
"Hello World!".take (..Every 2 first=6) == "Wrd"
|
||||
"Hello World!".take (..Every 3) == "Hl Wl"
|
||||
"Hello World!".take (..By_Index 0) == "H"
|
||||
"Hello World!".take (..By_Index [1, 0, 0, 6, 0]) == "eHHWH"
|
||||
"Hello World!".take (..By_Index [Range 0 3, 6, Range 6 12 2]) == "HelWWrd"
|
||||
"Hello World!".take (..Sample 3 seed=42) == "l d"
|
||||
@range Text_Sub_Range.default_widget
|
||||
Text.take : (Text_Sub_Range | Index_Sub_Range | Range | Integer) -> Text ! Index_Out_Of_Bounds
|
||||
Text.take self range=(Index_Sub_Range.First 1) =
|
||||
Text.take self range:(Text_Sub_Range | Index_Sub_Range | Range | Integer)=..First =
|
||||
ranges = Codepoint_Ranges.resolve self range
|
||||
case ranges of
|
||||
Range.Between start end 1 ->
|
||||
@ -1082,29 +1082,29 @@ Text.take self range=(Index_Sub_Range.First 1) =
|
||||
> Example
|
||||
Various different ways to take part of "Hello World!"
|
||||
|
||||
"Hello World!".drop First == "ello World!"
|
||||
"Hello World!".drop (First 5) == " World!"
|
||||
"Hello World!".drop (First 0) == "Hello World!"
|
||||
"Hello World!".drop Last == "Hello World"
|
||||
"Hello World!".drop (Last 6) == "Hello "
|
||||
"Hello World!".drop (Before " ") == " World!"
|
||||
"Hello World!".drop (Before_Last "o") == "orld!"
|
||||
"Hello World!".drop (After " ") == "Hello "
|
||||
"Hello World!".drop (After_Last "o") == "Hello Wo"
|
||||
"Hello World!".drop (While c->c!=" ") == " World!"
|
||||
"Hello World!".drop (Range 3 5) == "Hel World!"
|
||||
"Hello World!".drop (Range 5 Nothing) == "Hello"
|
||||
"Hello World!".drop (Range 5 12) == "Hello"
|
||||
"Hello World!".drop (Range 6 12 2) == "Hello ol!"
|
||||
"Hello World!".drop (Every 2 first=6) == "Hello ol!"
|
||||
"Hello World!".drop (Every 3) == "elo ord!"
|
||||
"Hello World!".drop (By_Index 0) == "ello World!"
|
||||
"Hello World!".drop (By_Index [1, 0, 0, 6, 0]) == "llo orld!"
|
||||
"Hello World!".drop (By_Index [Range 0 3, 6, Range 6 12 2]) == "lo ol!"
|
||||
"Hello World!".drop (Sample 3 seed=42) == "HeloWorl!"
|
||||
"Hello World!".drop ..First == "ello World!"
|
||||
"Hello World!".drop (..First 5) == " World!"
|
||||
"Hello World!".drop (..First 0) == "Hello World!"
|
||||
"Hello World!".drop ..Last == "Hello World"
|
||||
"Hello World!".drop (..Last 6) == "Hello "
|
||||
"Hello World!".drop (..Before " ") == " World!"
|
||||
"Hello World!".drop (..Before_Last "o") == "orld!"
|
||||
"Hello World!".drop (..After " ") == "Hello "
|
||||
"Hello World!".drop (..After_Last "o") == "Hello Wo"
|
||||
"Hello World!".drop (..While c->c!=" ") == " World!"
|
||||
"Hello World!".drop (..Range 3 5) == "Hel World!"
|
||||
"Hello World!".drop (..Range 5 Nothing) == "Hello"
|
||||
"Hello World!".drop (..Range 5 12) == "Hello"
|
||||
"Hello World!".drop (..Range 6 12 2) == "Hello ol!"
|
||||
"Hello World!".drop (..Every 2 first=6) == "Hello ol!"
|
||||
"Hello World!".drop (..Every 3) == "elo ord!"
|
||||
"Hello World!".drop (..By_Index 0) == "ello World!"
|
||||
"Hello World!".drop (..By_Index [1, 0, 0, 6, 0]) == "llo orld!"
|
||||
"Hello World!".drop (..By_Index [Range 0 3, 6, Range 6 12 2]) == "lo ol!"
|
||||
"Hello World!".drop (..Sample 3 seed=42) == "HeloWorl!"
|
||||
@range Text_Sub_Range.default_widget
|
||||
Text.drop : (Text_Sub_Range | Index_Sub_Range | Range) -> Text ! Index_Out_Of_Bounds
|
||||
Text.drop self range=(Index_Sub_Range.First 1) =
|
||||
Text.drop self range:(Text_Sub_Range | Index_Sub_Range | Range | Integer)=..First =
|
||||
ranges = Codepoint_Ranges.resolve self range
|
||||
case ranges of
|
||||
Range.Between start end 1 ->
|
||||
@ -1197,9 +1197,9 @@ Text.pad self length:Integer=0 with_pad:Text=' ' at:Location=..Right = case at o
|
||||
remainder = pad_size % with_pad_length
|
||||
case at of
|
||||
Location.Left ->
|
||||
with_pad.take (Index_Sub_Range.Last remainder) + with_pad.repeat full_repetitions + self
|
||||
with_pad.take (..Last remainder) + with_pad.repeat full_repetitions + self
|
||||
Location.Right ->
|
||||
self + with_pad.repeat full_repetitions + with_pad.take (Index_Sub_Range.First remainder)
|
||||
self + with_pad.repeat full_repetitions + with_pad.take (..First remainder)
|
||||
|
||||
## GROUP Text
|
||||
ICON text
|
||||
|
@ -1,4 +1,3 @@
|
||||
import project.Data.Index_Sub_Range as Index_Sub_Range_Module
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Pair.Pair
|
||||
@ -16,7 +15,7 @@ import project.Nothing.Nothing
|
||||
import project.Panic.Panic
|
||||
import project.Random.Random
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Index_Sub_Range import handle_unmatched_type
|
||||
from project.Data.Index_Sub_Range import handle_unmatched_type, sort_and_merge_ranges
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Metadata.Choice import Option
|
||||
from project.Metadata.Widget import Single_Choice
|
||||
@ -56,10 +55,10 @@ type Text_Sub_Range
|
||||
## PRIVATE
|
||||
default_options : Vector Option
|
||||
default_options =
|
||||
o1 = Option "Before" "(Text_Sub_Range.Before ' ')"
|
||||
o2 = Option "Before_Last" "(Text_Sub_Range.Before_Last ' ')"
|
||||
o3 = Option "After" "(Text_Sub_Range.After ' ')"
|
||||
o4 = Option "After_Last" "(Text_Sub_Range.After_Last ' ')"
|
||||
o1 = Option "Before" "(..Before ' ')"
|
||||
o2 = Option "Before_Last" "(..Before_Last ' ')"
|
||||
o3 = Option "After" "(..After ' ')"
|
||||
o4 = Option "After_Last" "(..After_Last ' ')"
|
||||
[o1, o2, o3, o4]
|
||||
|
||||
## PRIVATE
|
||||
@ -89,7 +88,7 @@ type Codepoint_Ranges
|
||||
Empty ranges are not discarded.
|
||||
sorted_and_distinct_ranges : Vector Range
|
||||
sorted_and_distinct_ranges self = if self.is_sorted_and_distinct then self.ranges else
|
||||
Index_Sub_Range_Module.sort_and_merge_ranges self.ranges
|
||||
sort_and_merge_ranges self.ranges
|
||||
|
||||
## PRIVATE
|
||||
Finds code-point indices corresponding to the part of the input matching the
|
||||
@ -102,7 +101,7 @@ type Codepoint_Ranges
|
||||
in such a way that the ranges returned by this method always have a step
|
||||
equal to 1.
|
||||
resolve : Text -> (Text_Sub_Range | Index_Sub_Range | Range | Integer) -> (Range | Codepoint_Ranges)
|
||||
resolve text range =
|
||||
resolve text:Text range:(Text_Sub_Range | Index_Sub_Range | Range | Integer) =
|
||||
case range of
|
||||
Text_Sub_Range.Before delimiter ->
|
||||
if delimiter.is_empty then (0.up_to 0) else
|
||||
@ -151,13 +150,13 @@ type Codepoint_Ranges
|
||||
Index_Sub_Range.Sample count seed ->
|
||||
rng = Random.new_generator seed
|
||||
indices = rng.indices text.length count
|
||||
Codepoint_Ranges.resolve text (Index_Sub_Range.By_Index indices)
|
||||
Codepoint_Ranges.resolve text (..By_Index indices)
|
||||
Index_Sub_Range.Every step start ->
|
||||
if step <= 0 then Error.throw (Illegal_Argument.Error "Step within Every must be positive.") else
|
||||
len = text.length
|
||||
if start >= len then 0.up_to 0 else
|
||||
simple_range = start.up_to text.length . with_step step
|
||||
Codepoint_Ranges.resolve text (Index_Sub_Range.By_Index simple_range)
|
||||
Codepoint_Ranges.resolve text (..By_Index simple_range)
|
||||
_ : Range ->
|
||||
Codepoint_Ranges.resolve text (Index_Sub_Range.By_Index range)
|
||||
_ : Integer ->
|
||||
|
@ -974,7 +974,7 @@ type Vector a
|
||||
If a `Range`, the selection is specified by two indices, from and to.
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Vector Any
|
||||
take self range=(Index_Sub_Range.First 1) =
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Array_Like_Helpers.take self range
|
||||
|
||||
## ALIAS skip, remove
|
||||
@ -989,7 +989,7 @@ type Vector a
|
||||
If a `Range`, the selection is specified by two indices, from and to.
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Vector Any
|
||||
drop self range=(Index_Sub_Range.First 1) =
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Array_Like_Helpers.drop self range
|
||||
|
||||
## ALIAS combine, join by row position, merge
|
||||
|
@ -39,7 +39,6 @@ import project.System.File_Format_Metadata.File_Format_Metadata
|
||||
import project.System.Input_Stream.Input_Stream
|
||||
import project.System.Output_Stream.Output_Stream
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Index_Sub_Range.Index_Sub_Range import Last
|
||||
from project.Data.Text.Extensions import all
|
||||
from project.Enso_Cloud.Internal.Enso_File_Helpers import all
|
||||
from project.Enso_Cloud.Public_Utils import get_required_field
|
||||
|
@ -1,7 +1,6 @@
|
||||
private
|
||||
|
||||
import project.Any.Any
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.Json.Invalid_JSON
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Map.Map
|
||||
@ -115,7 +114,7 @@ create_datalink_from_stream_action (destination : Enso_File) (allow_existing : B
|
||||
if existing_asset.is_nothing.not && existing_asset.asset_type != Enso_Asset_Type.Data_Link then Error.throw (Illegal_Argument.Error "The destination must be a path to a Data Link, not "+existing_asset.asset_type.to_text+".") else
|
||||
file_name = destination.name
|
||||
if file_name.ends_with data_link_extension . not then Error.throw (Illegal_Argument.Error "A datalink must have a name ending with "+data_link_extension+", but the provided name was: "+file_name) else
|
||||
title = file_name.drop (Index_Sub_Range.Last data_link_extension.length)
|
||||
title = file_name.drop (..Last data_link_extension.length)
|
||||
stream_result = Output_Stream.with_memory_stream stream_action
|
||||
raw_bytes = stream_result.first
|
||||
action_result = stream_result.second
|
||||
|
@ -1,6 +1,5 @@
|
||||
private
|
||||
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Vector.Vector
|
||||
import project.Enso_Cloud.Enso_File.Enso_File
|
||||
@ -42,7 +41,7 @@ type Enso_Path
|
||||
## PRIVATE
|
||||
parent self -> Enso_Path =
|
||||
if self.is_root then Error.throw (Illegal_Argument.Error "Cannot get parent of the root directory.") else
|
||||
Enso_Path.Value self.organization_name (self.path_segments.drop (Index_Sub_Range.Last 1))
|
||||
Enso_Path.Value self.organization_name (self.path_segments.drop (..Last 1))
|
||||
|
||||
## PRIVATE
|
||||
resolve self (subpath : Text) -> Enso_Path =
|
||||
|
@ -3,7 +3,6 @@ private
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Map.Map
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
|
||||
import project.Data.Time.Date_Time.Date_Time
|
||||
import project.Data.Time.Date_Time_Formatter.Date_Time_Formatter
|
||||
import project.Data.Vector.Vector
|
||||
@ -112,7 +111,7 @@ type Existing_Enso_Asset
|
||||
|
||||
## PRIVATE
|
||||
from_id_and_title id:Text title:Text -> Existing_Enso_Asset =
|
||||
asset_type = Enso_Asset_Type.from (id.take (Text_Sub_Range.Before "-"))
|
||||
asset_type = Enso_Asset_Type.from (id.take (..Before "-"))
|
||||
Existing_Enso_Asset.Value title id asset_type
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ private
|
||||
import project.Any.Any
|
||||
import project.Data.Array.Array
|
||||
import project.Data.Array_Proxy.Array_Proxy
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.List.List
|
||||
import project.Data.Map.Map
|
||||
import project.Data.Maybe.Maybe
|
||||
@ -25,7 +26,7 @@ import project.Runtime.Ref.Ref
|
||||
import project.Warning.Warning
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Filter_Condition import unify_condition_or_predicate, unify_condition_predicate_or_element
|
||||
from project.Data.Index_Sub_Range import drop_helper, Index_Sub_Range, take_helper
|
||||
from project.Data.Index_Sub_Range import drop_helper, take_helper
|
||||
from project.Data.Ordering import Comparable
|
||||
from project.Data.Range.Extensions import all
|
||||
|
||||
@ -310,7 +311,7 @@ to_list vector =
|
||||
|
||||
short_display_text vector max_entries =
|
||||
if max_entries < 1 then Error.throw <| Illegal_Argument.Error "The `max_entries` parameter must be positive." else
|
||||
prefix = vector.take (Index_Sub_Range.First max_entries)
|
||||
prefix = vector.take (..First max_entries)
|
||||
if prefix.length == vector.length then vector.to_text else
|
||||
remaining_count = vector.length - prefix.length
|
||||
remaining_text = if remaining_count == 1 then "and 1 more element" else
|
||||
|
@ -94,7 +94,6 @@ export project.System.Process
|
||||
export project.System.Process.Exit_Code.Exit_Code
|
||||
export project.Warning.Warning
|
||||
from project.Data.Boolean export Boolean, False, True
|
||||
from project.Data.Index_Sub_Range.Index_Sub_Range export First, Last
|
||||
from project.Data.Json.Extensions export all
|
||||
from project.Data.Numbers export Float, Integer, Number
|
||||
from project.Data.Range.Extensions export all
|
||||
|
@ -5,7 +5,6 @@ import project.Data.Numbers.Integer
|
||||
import project.Data.Numbers.Number
|
||||
import project.Data.Text.Encoding.Encoding
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.File_Error.File_Error
|
||||
@ -226,7 +225,7 @@ resolve_file_metadata_for_response : Response -> File_Format_Metadata
|
||||
resolve_file_metadata_for_response response =
|
||||
uri_as_text = response.uri.to_text
|
||||
guessed_filename = filename_from_content_disposition (response.get_header "Content-Disposition") . if_nothing <|
|
||||
last_path_segment = uri_as_text.take (Text_Sub_Range.After_Last "/")
|
||||
last_path_segment = uri_as_text.take (..After_Last "/")
|
||||
## Heuristic: If the last path segment contains a dot, it is likely a filename,
|
||||
otherwise it is too unlikely + lack of extension will not help our guessing anyway,
|
||||
so we can discard it.
|
||||
|
@ -15,7 +15,6 @@ import project.Polyglot.Polyglot
|
||||
import project.Runtime.Source_Location.Source_Location
|
||||
import project.System
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Index_Sub_Range.Index_Sub_Range import First, Last
|
||||
from project.Data.Text.Extensions import all
|
||||
from project.Runtime.Context import Input, Output
|
||||
|
||||
@ -37,7 +36,7 @@ get_stack_trace : Vector Stack_Trace_Element
|
||||
get_stack_trace =
|
||||
prim_stack = primitive_get_stack_trace
|
||||
stack_with_own_frame = Vector.from_polyglot_array prim_stack
|
||||
stack = stack_with_own_frame.drop (First 1)
|
||||
stack = stack_with_own_frame.drop (..First 1)
|
||||
stack.map wrap_primitive_stack_trace_element
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1,13 +1,11 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Array.Array
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Text.Encoding.Encoding
|
||||
import project.Data.Text.Extensions
|
||||
import project.Data.Text.Matching_Mode.Matching_Mode
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
|
||||
import project.Data.Time.Date_Time.Date_Time
|
||||
import project.Data.Vector.Vector
|
||||
import project.Enso_Cloud.Data_Link.Data_Link
|
||||
@ -874,7 +872,7 @@ get_child_widget file =
|
||||
## PRIVATE
|
||||
find_extension_from_name : Text -> Text
|
||||
find_extension_from_name name =
|
||||
extension = name.drop (Text_Sub_Range.Before_Last ".")
|
||||
extension = name.drop (..Before_Last ".")
|
||||
if extension == "." then "" else extension
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1,6 +1,5 @@
|
||||
import project.Any.Any
|
||||
import project.Data.Array.Array
|
||||
import project.Data.Index_Sub_Range.Index_Sub_Range
|
||||
import project.Data.Maybe.Maybe
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Pair.Pair
|
||||
@ -27,7 +26,7 @@ type Warning
|
||||
attach : Any -> Any -> Any
|
||||
attach warning value =
|
||||
origin = Runtime.get_stack_trace
|
||||
attach_with_stacktrace value warning (origin.drop (Index_Sub_Range.First 1))
|
||||
attach_with_stacktrace value warning (origin.drop (..First 1))
|
||||
|
||||
## PRIVATE
|
||||
ADVANCED
|
||||
@ -332,8 +331,8 @@ map_attached_warnings_helper mapper value frames_to_drop =
|
||||
Maybe.Some new_payload ->
|
||||
self_call_name = "Warning.map_attached_warnings_helper"
|
||||
stack_trace = Runtime.get_stack_trace
|
||||
stack_trace_up_to_this_function = stack_trace.drop (Index_Sub_Range.While element-> element.name != self_call_name)
|
||||
new_origin = stack_trace_up_to_this_function.drop (Index_Sub_Range.First 1+frames_to_drop)
|
||||
stack_trace_up_to_this_function = stack_trace.drop (..While element-> element.name != self_call_name)
|
||||
new_origin = stack_trace_up_to_this_function.drop (..First 1+frames_to_drop)
|
||||
create new_payload new_origin
|
||||
## If the mapper did not want to affect this warning, we return the
|
||||
original (unwrapped) warning instance.
|
||||
|
@ -1208,7 +1208,7 @@ type DB_Column
|
||||
- range: The selection of rows from the table to return.
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> DB_Column
|
||||
take self range=(First 1) = self.to_table.take range . at 0
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First = self.to_table.take range . at 0
|
||||
|
||||
## ALIAS remove, skip
|
||||
GROUP Standard.Base.Selections
|
||||
@ -1220,7 +1220,7 @@ type DB_Column
|
||||
- range: The selection of rows from the table to remove.
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> DB_Column
|
||||
drop self range=(First 1) = self.to_table.drop range . at 0
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First = self.to_table.drop range . at 0
|
||||
|
||||
## GROUP Standard.Base.Text
|
||||
ICON preparation
|
||||
|
@ -757,7 +757,7 @@ type DB_Table
|
||||
> Example
|
||||
Take first 10 rows of the table.
|
||||
|
||||
table.take (First 10)
|
||||
table.take (..First 10)
|
||||
|
||||
> Example
|
||||
Take rows from the top of the table as long as their values sum to 10.
|
||||
@ -765,7 +765,7 @@ type DB_Table
|
||||
table.take (While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> DB_Table
|
||||
take self range:(Index_Sub_Range | Range | Integer)=(..First 1) =
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Take_Drop_Helpers.take_drop_helper Take_Drop.Take self range
|
||||
|
||||
## ALIAS remove, skip
|
||||
@ -789,7 +789,7 @@ type DB_Table
|
||||
> Example
|
||||
Drop first 10 rows of the table.
|
||||
|
||||
table.drop (First 10)
|
||||
table.drop (..First 10)
|
||||
|
||||
> Example
|
||||
Drop rows from the top of the table as long as their values sum to 10.
|
||||
@ -797,7 +797,7 @@ type DB_Table
|
||||
table.drop (While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> DB_Table
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=(..First 1) =
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
Take_Drop_Helpers.take_drop_helper Take_Drop.Drop self range
|
||||
|
||||
## PRIVATE
|
||||
|
@ -41,12 +41,12 @@ type SQL_Error
|
||||
we don't shorten them too much. We impose an upper limit to avoid unbounded error message size.
|
||||
max_length = 1000
|
||||
shortened_query_text = if query_text.length <= max_length then query_text else
|
||||
query_text.take (Index_Sub_Range.First (max_length.div 2)) + " (...) " + query_text.take (Index_Sub_Range.Last (max_length.div 2))
|
||||
query_text.take (..First (max_length.div 2)) + " (...) " + query_text.take (..Last (max_length.div 2))
|
||||
" [Query was: " + shortened_query_text + "]"
|
||||
message = self.java_exception.getMessage
|
||||
max_length = 300
|
||||
short_message = if message.length < max_length then message else
|
||||
message.take (Index_Sub_Range.First (max_length.div 2)) + " (...) " + message.take (Index_Sub_Range.Last (max_length.div 2))
|
||||
message.take (..First (max_length.div 2)) + " (...) " + message.take (..Last (max_length.div 2))
|
||||
"There was an SQL error: " + short_message + "." + query
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1,9 +1,8 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
import Standard.Table.Internal.Problem_Builder.Problem_Builder
|
||||
from Standard.Table import Aggregate_Column
|
||||
from Standard.Table.Aggregate_Column.Aggregate_Column import all
|
||||
from Standard.Table.Errors import Floating_Point_Equality
|
||||
|
||||
import project.DB_Table.DB_Table
|
||||
@ -42,49 +41,49 @@ make_aggregate_column table aggregate as dialect infer_return_type problem_build
|
||||
Internal_Column.Value as sql_type_ref expression
|
||||
|
||||
dialect.check_aggregate_support aggregate . if_not_error <| case aggregate of
|
||||
Group_By c _ ->
|
||||
Aggregate_Column.Group_By c _ ->
|
||||
Internal_Column.Value as c.sql_type_reference c.expression
|
||||
Count _ -> simple_aggregate "COUNT_ROWS" []
|
||||
Count_Distinct columns _ ignore_nothing -> if columns.is_empty then Error.throw (Illegal_Argument.Error "Count_Distinct must have at least one column.") else
|
||||
Aggregate_Column.Count _ -> simple_aggregate "COUNT_ROWS" []
|
||||
Aggregate_Column.Count_Distinct columns _ ignore_nothing -> if columns.is_empty then Error.throw (Illegal_Argument.Error "Count_Distinct must have at least one column.") else
|
||||
case ignore_nothing of
|
||||
True -> simple_aggregate "COUNT_DISTINCT" columns
|
||||
False -> simple_aggregate "COUNT_DISTINCT_INCLUDE_NULL" columns
|
||||
Count_Not_Nothing c _ -> simple_aggregate "COUNT" [c]
|
||||
Count_Nothing c _ -> simple_aggregate "COUNT_IS_NULL" [c]
|
||||
Count_Not_Empty c _ -> simple_aggregate "COUNT_NOT_EMPTY" [c]
|
||||
Count_Empty c _ -> simple_aggregate "COUNT_EMPTY" [c]
|
||||
Percentile p c _ ->
|
||||
Aggregate_Column.Count_Not_Nothing c _ -> simple_aggregate "COUNT" [c]
|
||||
Aggregate_Column.Count_Nothing c _ -> simple_aggregate "COUNT_IS_NULL" [c]
|
||||
Aggregate_Column.Count_Not_Empty c _ -> simple_aggregate "COUNT_NOT_EMPTY" [c]
|
||||
Aggregate_Column.Count_Empty c _ -> simple_aggregate "COUNT_EMPTY" [c]
|
||||
Aggregate_Column.Percentile p c _ ->
|
||||
op_kind = "PERCENTILE"
|
||||
expression = SQL_Expression.Operation op_kind [SQL_Expression.Literal p.to_text, c.expression]
|
||||
sql_type_ref = infer_return_type op_kind [c] expression
|
||||
Internal_Column.Value as sql_type_ref expression
|
||||
Mode c _ ->
|
||||
Aggregate_Column.Mode c _ ->
|
||||
col = table.make_column c
|
||||
if col.value_type.is_floating_point then
|
||||
problem_builder.report_other_warning (Floating_Point_Equality.Error as)
|
||||
simple_aggregate "MODE" [c]
|
||||
First c _ ignore_nothing order_by -> case is_non_empty_selector order_by of
|
||||
Aggregate_Column.First c _ ignore_nothing order_by -> case is_non_empty_selector order_by of
|
||||
False -> Error.throw (Unsupported_Database_Operation.Error "`First` aggregation requires at least one `order_by` column.")
|
||||
True ->
|
||||
op = case ignore_nothing of
|
||||
False -> "FIRST"
|
||||
True -> "FIRST_NOT_NULL"
|
||||
aggregate_with_order_by op c order_by
|
||||
Last c _ ignore_nothing order_by -> case is_non_empty_selector order_by of
|
||||
Aggregate_Column.Last c _ ignore_nothing order_by -> case is_non_empty_selector order_by of
|
||||
False -> Error.throw (Unsupported_Database_Operation.Error "`Last` aggregation requires at least one `order_by` column.")
|
||||
True ->
|
||||
op = case ignore_nothing of
|
||||
False -> "LAST"
|
||||
True -> "LAST_NOT_NULL"
|
||||
aggregate_with_order_by op c order_by
|
||||
Maximum c _ -> simple_aggregate "MAX" [c]
|
||||
Minimum c _ -> simple_aggregate "MIN" [c]
|
||||
Shortest c _ -> simple_aggregate "SHORTEST" [c]
|
||||
Longest c _ -> simple_aggregate "LONGEST" [c]
|
||||
Standard_Deviation c _ population -> case population of
|
||||
Aggregate_Column.Maximum c _ -> simple_aggregate "MAX" [c]
|
||||
Aggregate_Column.Minimum c _ -> simple_aggregate "MIN" [c]
|
||||
Aggregate_Column.Shortest c _ -> simple_aggregate "SHORTEST" [c]
|
||||
Aggregate_Column.Longest c _ -> simple_aggregate "LONGEST" [c]
|
||||
Aggregate_Column.Standard_Deviation c _ population -> case population of
|
||||
True -> simple_aggregate "STDDEV_POP" [c]
|
||||
False -> simple_aggregate "STDDEV_SAMP" [c]
|
||||
Concatenate c _ separator prefix suffix quote_char ->
|
||||
Aggregate_Column.Concatenate c _ separator prefix suffix quote_char ->
|
||||
base_args = [c.expression, SQL_Expression.Constant separator, SQL_Expression.Constant prefix, SQL_Expression.Constant suffix]
|
||||
op_kind = case quote_char.is_empty of
|
||||
True -> "CONCAT"
|
||||
@ -96,6 +95,6 @@ make_aggregate_column table aggregate as dialect infer_return_type problem_build
|
||||
expression = SQL_Expression.Operation op_kind effective_args
|
||||
sql_type_ref = infer_return_type op_kind [c] expression
|
||||
Internal_Column.Value as sql_type_ref expression
|
||||
Sum c _ -> simple_aggregate "SUM" [c]
|
||||
Average c _ -> simple_aggregate "AVG" [c]
|
||||
Median c _ -> simple_aggregate "MEDIAN" [c]
|
||||
Aggregate_Column.Sum c _ -> simple_aggregate "SUM" [c]
|
||||
Aggregate_Column.Average c _ -> simple_aggregate "AVG" [c]
|
||||
Aggregate_Column.Median c _ -> simple_aggregate "MEDIAN" [c]
|
||||
|
@ -227,7 +227,7 @@ case_when : Vector SQL_Builder -> SQL_Builder
|
||||
case_when arguments =
|
||||
if arguments.length < 3 then Error.throw (Illegal_State.Error "CASE_WHEN needs at least 3 arguments.") else
|
||||
fallback = arguments.last
|
||||
cases = arguments.drop (Last 1)
|
||||
cases = arguments.drop (..Last 1)
|
||||
if cases.length % 2 != 0 then Error.throw (Illegal_State.Error "CASE_WHEN expects an odd number of arguments (two arguments for each case and a fallback).") else
|
||||
n = cases.length . div 2
|
||||
cases_exprs = 0.up_to n . map i->
|
||||
@ -279,8 +279,8 @@ make_row_number (arguments : Vector) (metadata : Row_Number_Metadata) = if argum
|
||||
step = arguments.at 1
|
||||
|
||||
ordering_and_grouping = arguments.drop 2
|
||||
ordering = ordering_and_grouping.drop (Last metadata.groupings_count)
|
||||
grouping = ordering_and_grouping.take (Last metadata.groupings_count)
|
||||
ordering = ordering_and_grouping.drop (..Last metadata.groupings_count)
|
||||
grouping = ordering_and_grouping.take (..Last metadata.groupings_count)
|
||||
|
||||
group_part = if grouping.length == 0 then "" else
|
||||
SQL_Builder.code "PARTITION BY " ++ SQL_Builder.join ", " grouping
|
||||
|
@ -54,7 +54,7 @@ prepare_credentials data_link_location:Enso_File details:Postgres -> JS_Object |
|
||||
secret : Enso_Secret -> secret
|
||||
plain_text_password : Text ->
|
||||
secret_location = data_link_location.parent.if_nothing Enso_File.root
|
||||
location_name = if data_link_location.name.ends_with data_link_extension then data_link_location.name.drop (Index_Sub_Range.Last data_link_extension.length) else data_link_location.name
|
||||
location_name = if data_link_location.name.ends_with data_link_extension then data_link_location.name.drop (..Last data_link_extension.length) else data_link_location.name
|
||||
|
||||
create_fresh_secret ix =
|
||||
secret_name = location_name + "-password" + (if ix == 0 then "" else "-"+ix.to_text)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Errors.Unimplemented.Unimplemented
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Runtime.Ref.Ref
|
||||
|
@ -175,12 +175,12 @@ operations_map =
|
||||
|
||||
handle_case arguments =
|
||||
fallback = arguments.last
|
||||
cases = arguments.drop (Last 1)
|
||||
cases = arguments.drop (..Last 1)
|
||||
if cases.length % 2 != 0 then
|
||||
Panic.throw (Illegal_State.Error "Impossible: constructed a CASE with an odd number of case arguments.")
|
||||
if cases.is_empty then
|
||||
Panic.throw (Illegal_State.Error "Impossible: too few cases provided for a CASE statement.")
|
||||
case_results = cases.take (Index_Sub_Range.Every 2 first=1)
|
||||
case_results = cases.take (..Every 2 first=1)
|
||||
possible_results = case_results + [fallback]
|
||||
find_a_common_type possible_results
|
||||
|
||||
|
@ -238,7 +238,7 @@ raise_duplicated_primary_key_error source_table primary_key original_panic =
|
||||
False ->
|
||||
row = materialized.first_row.to_vector
|
||||
example_count = row.last
|
||||
example_entry = row.drop (Last 1)
|
||||
example_entry = row.drop (..Last 1)
|
||||
Error.throw (Non_Unique_Key.Error primary_key example_entry example_count)
|
||||
|
||||
## PRIVATE
|
||||
@ -624,7 +624,7 @@ check_multiple_rows_match left_table right_table key_columns ~continuation =
|
||||
True -> continuation
|
||||
False ->
|
||||
row = example.first_row . to_vector
|
||||
offending_key = row.drop (Last 1)
|
||||
offending_key = row.drop (..Last 1)
|
||||
count = row.last
|
||||
Error.throw (Multiple_Target_Rows_Matched_For_Update.Error offending_key count)
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
from Standard.Base import all
|
||||
|
||||
import Standard.Base.Data.Index_Sub_Range as Index_Sub_Range_Module
|
||||
import Standard.Base.Data.Vector.No_Wrap
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
from Standard.Base.Data.Index_Sub_Range import normalize_ranges, resolve_ranges, sort_and_merge_ranges
|
||||
from Standard.Base.Data.Index_Sub_Range import drop_helper, normalize_ranges, resolve_ranges, sort_and_merge_ranges, take_helper
|
||||
|
||||
from Standard.Table import Set_Mode
|
||||
|
||||
@ -22,7 +21,7 @@ type Take_Drop
|
||||
## PRIVATE
|
||||
Apply `take` or `drop` to a table, returning the specified by the selector.
|
||||
take_drop_helper : Take_Drop -> DB_Table -> (Index_Sub_Range | Range | Integer) -> DB_Table
|
||||
take_drop_helper take_drop table selector =
|
||||
take_drop_helper take_drop table selector:(Index_Sub_Range | Range | Integer) =
|
||||
check_supported selector <|
|
||||
length = table.row_count
|
||||
ranges = cleanup_ranges (collect_ranges take_drop length selector)
|
||||
@ -40,7 +39,7 @@ take_drop_helper take_drop table selector =
|
||||
## PRIVATE
|
||||
Turn the selector into a vector of ranges
|
||||
collect_ranges : Take_Drop -> Integer -> (Index_Sub_Range | Range | Integer) -> Vector Range
|
||||
collect_ranges take_drop length selector =
|
||||
collect_ranges take_drop length selector:(Index_Sub_Range | Range | Integer) =
|
||||
at _ = Panic.throw (Illegal_State.Error "Impossible: at called in Database take/drop. This is a bug in the Database library.")
|
||||
single_slice s e = [Range.new s e]
|
||||
slice_ranges selectors =
|
||||
@ -49,14 +48,14 @@ collect_ranges take_drop length selector =
|
||||
r : Range -> r
|
||||
selectors.map slice_range
|
||||
helper = case take_drop of
|
||||
Take_Drop.Take -> Index_Sub_Range_Module.take_helper
|
||||
Take_Drop.Drop -> Index_Sub_Range_Module.drop_helper
|
||||
Take_Drop.Take -> take_helper
|
||||
Take_Drop.Drop -> drop_helper
|
||||
helper length at single_slice slice_ranges selector
|
||||
|
||||
## PRIVATE
|
||||
Throw Unsupported_Database_Operation for selectors that are not supported by database backends.
|
||||
check_supported : (Index_Sub_Range | Range | Integer) -> Any -> Any | Unsupported_Database_Operation
|
||||
check_supported selector ~cont =
|
||||
check_supported selector:(Index_Sub_Range | Range | Integer) ~cont =
|
||||
err =
|
||||
msg = selector.to_display_text + " is not supported for database backends"
|
||||
Error.throw (Unsupported_Database_Operation.Error msg)
|
||||
|
@ -1,6 +1,6 @@
|
||||
private
|
||||
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Errors.Unimplemented.Unimplemented
|
||||
|
@ -1,6 +1,5 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.Array_Proxy.Array_Proxy
|
||||
import Standard.Base.Data.Index_Sub_Range as Index_Sub_Range_Module
|
||||
import Standard.Base.Data.Vector.No_Wrap
|
||||
import Standard.Base.Errors.Common.Arithmetic_Error
|
||||
import Standard.Base.Errors.Common.Incomparable_Values
|
||||
@ -12,6 +11,7 @@ import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Internal.Polyglot_Helpers
|
||||
import Standard.Base.Internal.Rounding_Helpers
|
||||
from Standard.Base.Metadata.Widget import Numeric_Input
|
||||
from Standard.Base.Data.Index_Sub_Range import drop_helper, normalize_ranges, take_helper
|
||||
from Standard.Base.Widget_Helpers import make_data_cleanse_vector_selector, make_format_chooser, make_regex_text_widget
|
||||
|
||||
import project.Constants.Previous_Value
|
||||
@ -2404,7 +2404,7 @@ type Column
|
||||
table = Table.new [["Name", ["Alice", "Bob", "Charlie"]]]
|
||||
column = table.get "Name"
|
||||
## The take returns "Alice"
|
||||
first_row = column.take (First 1)
|
||||
first_row = column.take (..First 1)
|
||||
|
||||
> Example
|
||||
Select the last row from the "Name" Column.
|
||||
@ -2412,11 +2412,11 @@ type Column
|
||||
table = Table.new [["Name", ["Alice", "Bob", "Charlie"]]]
|
||||
column = table.get "Name"
|
||||
## The take returns "Charlie"
|
||||
last_row = column.take (Last 1)
|
||||
last_row = column.take (..Last 1)
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Column
|
||||
take self range=(First 1) =
|
||||
Index_Sub_Range_Module.take_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
take_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## ALIAS remove, skip
|
||||
GROUP Standard.Base.Selections
|
||||
@ -2428,8 +2428,8 @@ type Column
|
||||
- range: The selection of rows from the table to remove.
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Column
|
||||
drop self range=(First 1) =
|
||||
Index_Sub_Range_Module.drop_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
drop_helper self.length (self.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## PRIVATE
|
||||
Returns a column with a continuous sub-range of rows taken.
|
||||
@ -2710,7 +2710,7 @@ normalize_text_for_display text =
|
||||
## PRIVATE
|
||||
A helper to create a new table consisting of slices of the original table.
|
||||
slice_ranges column ranges =
|
||||
normalized = Index_Sub_Range_Module.normalize_ranges ranges
|
||||
normalized = normalize_ranges ranges
|
||||
Column.Value (column.java_column.slice normalized)
|
||||
|
||||
## PRIVATE
|
||||
|
@ -140,7 +140,7 @@ append_to_json_table file:File table on_problems:Problem_Behavior =
|
||||
case old_text.ends_with "]" && old_text.starts_with "[" of
|
||||
True ->
|
||||
## Here we read in the whole table. We could actually just read from the back and rely on `seek` to be more efficient for large files.
|
||||
new_text = old_text.drop (Last 1) + "," + table.to_json.drop (First 1)
|
||||
new_text = old_text.drop (..Last 1) + "," + table.to_json.drop (..First 1)
|
||||
new_text.write file on_existing_file=Existing_File_Behavior.Overwrite on_problems=on_problems
|
||||
False ->
|
||||
Error.throw (Invalid_JSON_Format.Error old_text "File already exists and is not a JSON array.")
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.Vector.No_Wrap
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
from Standard.Base.Runtime import assert
|
||||
|
@ -137,7 +137,7 @@ type Column_Naming_Helper
|
||||
# If there is too little space, we will just pick a few parts:
|
||||
True ->
|
||||
mid = Math.min (texts.length-1) (remaining_space.div min_bytes_per_part)
|
||||
texts.take (First 1+mid) + texts.take (Last 1)
|
||||
texts.take (..First 1+mid) + texts.take (..Last 1)
|
||||
False -> texts
|
||||
new_remaining_space = max_size - (separator_size * (parts_to_include.length - 1))
|
||||
initial_size_per_part = new_remaining_space.div parts_to_include.length
|
||||
|
@ -212,7 +212,7 @@ newline_at_eof file encoding =
|
||||
file_last_bytes = file.read_last_bytes most_bytes
|
||||
result = newlines.zip newline_bytes . find if_missing=[Nothing] pair->
|
||||
bytes = pair.second
|
||||
bytes == (file_last_bytes.take (Last bytes.length))
|
||||
bytes == (file_last_bytes.take (..Last bytes.length))
|
||||
result.first
|
||||
|
||||
## PRIVATE
|
||||
|
@ -58,8 +58,8 @@ print_table header rows indices_count format_term =
|
||||
divider = content_lengths . map (l -> "-".repeat l+2) . join '+'
|
||||
row_lines = rows.map r->
|
||||
x = r.zip content_lengths pad
|
||||
ixes = x.take (First indices_count) . map (ansi_bold format_term)
|
||||
with_bold_ix = ixes + x.drop (First indices_count)
|
||||
ixes = x.take (..First indices_count) . map (ansi_bold format_term)
|
||||
with_bold_ix = ixes + x.drop (..First indices_count)
|
||||
y = with_bold_ix . join ' | '
|
||||
" " + y
|
||||
([" " + header_line, divider] + row_lines).join '\n'
|
||||
|
@ -353,8 +353,8 @@ rename_columns (naming_helper : Column_Naming_Helper) (internal_columns:Vector)
|
||||
vec : Vector ->
|
||||
col_count = internal_columns.length
|
||||
good_names = if vec.length <= col_count then vec else
|
||||
problem_builder.report_other_warning (Too_Many_Column_Names_Provided.Error (vec.drop (First col_count)))
|
||||
vec.take (First col_count)
|
||||
problem_builder.report_other_warning (Too_Many_Column_Names_Provided.Error (vec.drop (..First col_count)))
|
||||
vec.take (..First col_count)
|
||||
internal_columns.take good_names.length . zip good_names
|
||||
_ : Map ->
|
||||
resolve_rename selector replacement = case selector of
|
||||
|
@ -39,7 +39,7 @@ type Rows_To_Read
|
||||
## PRIVATE
|
||||
attach_warning self input:Table -> Table = case self of
|
||||
Rows_To_Read.First_With_Warning rows -> if input.row_count <= rows then input else
|
||||
Problem_Behavior.Report_Warning.attach_problem_after (input.take (First rows)) <|
|
||||
Problem_Behavior.Report_Warning.attach_problem_after (input.take (..First rows)) <|
|
||||
Not_All_Rows_Downloaded.Warning rows
|
||||
_ -> input
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.Array_Proxy.Array_Proxy
|
||||
import Standard.Base.Data.Filter_Condition as Filter_Condition_Module
|
||||
import Standard.Base.Data.Index_Sub_Range as Index_Sub_Range_Module
|
||||
import Standard.Base.Data.Time.Errors.Date_Time_Format_Parse_Error
|
||||
import Standard.Base.Data.Vector.No_Wrap
|
||||
import Standard.Base.Errors.Common.Additional_Warnings
|
||||
@ -16,6 +15,7 @@ import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Unimplemented.Unimplemented
|
||||
import Standard.Base.Runtime.Context
|
||||
import Standard.Base.System.File.Generic.Writable_File.Writable_File
|
||||
from Standard.Base.Data.Index_Sub_Range import drop_helper, normalize_ranges, take_helper
|
||||
from Standard.Base.Metadata import Display, make_single_choice, Widget
|
||||
from Standard.Base.Widget_Helpers import make_any_selector, make_data_cleanse_vector_selector, make_delimiter_selector, make_format_chooser
|
||||
|
||||
@ -746,7 +746,7 @@ type Table
|
||||
problem_builder = Problem_Builder.new
|
||||
problem_builder.report_unique_name_strategy unique
|
||||
problem_builder.attach_problems_before on_problems <|
|
||||
self.drop (First 1) . rename_columns new_names_cleaned on_problems=on_problems
|
||||
self.drop (..First 1) . rename_columns new_names_cleaned on_problems=on_problems
|
||||
|
||||
## ALIAS group by, summarize
|
||||
GROUP Standard.Base.Calculations
|
||||
@ -1688,7 +1688,7 @@ type Table
|
||||
> Example
|
||||
Take first 10 rows of the table.
|
||||
|
||||
table.take (First 10)
|
||||
table.take (..First 10)
|
||||
|
||||
> Example
|
||||
Take rows from the top of the table as long as their values sum to 10.
|
||||
@ -1696,8 +1696,8 @@ type Table
|
||||
table.take (While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
@range Index_Sub_Range.default_widget
|
||||
take : (Index_Sub_Range | Range | Integer) -> Table
|
||||
take self range:(Index_Sub_Range | Range | Integer)=(..First 1) =
|
||||
Index_Sub_Range_Module.take_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
take self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
take_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## ALIAS remove, skip
|
||||
GROUP Standard.Base.Selections
|
||||
@ -1720,7 +1720,7 @@ type Table
|
||||
> Example
|
||||
Drop first 10 rows of the table.
|
||||
|
||||
table.drop (First 10)
|
||||
table.drop (..First 10)
|
||||
|
||||
> Example
|
||||
Drop rows from the top of the table as long as their values sum to 10.
|
||||
@ -1728,8 +1728,8 @@ type Table
|
||||
table.drop (While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
@range Index_Sub_Range.default_widget
|
||||
drop : (Index_Sub_Range | Range | Integer) -> Table
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=(..First 1) =
|
||||
Index_Sub_Range_Module.drop_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
drop self range:(Index_Sub_Range | Range | Integer)=..First =
|
||||
drop_helper self.row_count (self.rows.at _) self.slice (slice_ranges self) range
|
||||
|
||||
## PRIVATE
|
||||
Filter out all rows.
|
||||
@ -2481,9 +2481,9 @@ type Table
|
||||
read : Rows_To_Read -> Table
|
||||
read self (max_rows : Rows_To_Read = ..All_Rows) = case max_rows of
|
||||
Rows_To_Read.All_Rows -> self
|
||||
Rows_To_Read.First n -> self.take (First n)
|
||||
Rows_To_Read.First n -> self.take (..First n)
|
||||
Rows_To_Read.First_With_Warning n ->
|
||||
truncated = self.take (First n)
|
||||
truncated = self.take (..First n)
|
||||
if self.row_count <= n then truncated else
|
||||
Problem_Behavior.Report_Warning.attach_problem_after truncated <|
|
||||
Not_All_Rows_Downloaded.Warning n
|
||||
@ -3153,7 +3153,7 @@ type Table
|
||||
## PRIVATE
|
||||
A helper to create a new table consisting of slices of the original table.
|
||||
slice_ranges table ranges =
|
||||
normalized = Index_Sub_Range_Module.normalize_ranges ranges
|
||||
normalized = normalize_ranges ranges
|
||||
Table.Value (table.java_table.slice normalized)
|
||||
|
||||
## PRIVATE
|
||||
|
@ -213,7 +213,7 @@ Table.to_default_visualization_data self =
|
||||
row_count = ['number_of_rows', self.row_count]
|
||||
cols = self.columns.map c->
|
||||
name = c.name
|
||||
items = c.to_vector.take (First max_size)
|
||||
items = c.to_vector.take (..First max_size)
|
||||
JS_Object.from_pairs [['name', name], ['data', items]]
|
||||
JS_Object.from_pairs [row_count, ['columns', cols]] . to_text
|
||||
|
||||
@ -272,7 +272,7 @@ Column.to_default_visualization_data self =
|
||||
size = ['length', self.length]
|
||||
name = ['name', self.name]
|
||||
max_data = 100
|
||||
data = ['data', self.to_vector.take (First max_data)]
|
||||
data = ['data', self.to_vector.take (..First max_data)]
|
||||
JS_Object.from_pairs [size, name, data] . to_text
|
||||
|
||||
## PRIVATE
|
||||
|
@ -175,8 +175,8 @@ limit_data limit data = case limit of
|
||||
_ -> []
|
||||
extreme = Map.from_vector bounds error_on_duplicates=False . values
|
||||
|
||||
if limit <= extreme.length then extreme.take (First limit) else
|
||||
extreme + data.take (Index_Sub_Range.Sample (limit - extreme.length))
|
||||
if limit <= extreme.length then extreme.take (..First limit) else
|
||||
extreme + data.take (..Sample (limit - extreme.length))
|
||||
|
||||
## PRIVATE
|
||||
json_from_table : Table -> Vector Integer | Nothing -> Integer | Nothing -> Text
|
||||
|
@ -82,7 +82,7 @@ add_database_specs suite_builder create_connection_fn =
|
||||
agg_in_memory_table.select_into_database_table default_connection.get (Name_Generator.random_name "Agg1") primary_key=Nothing temporary=True
|
||||
|
||||
empty_agg_table_fn = _->
|
||||
(agg_in_memory_table.take (First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
(agg_in_memory_table.take (..First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
|
||||
setup = Common_Table_Operations.Main.Test_Setup.Config prefix agg_table_fn empty_agg_table_fn table_builder materialize is_database=True test_selection=common_selection aggregate_test_selection=aggregate_selection create_connection_func=create_connection_fn light_table_builder=light_table_builder
|
||||
Common_Table_Operations.Main.add_specs suite_builder setup
|
||||
|
@ -101,8 +101,8 @@ add_specs suite_builder =
|
||||
long = "Hello World! ".repeat 1024
|
||||
disp = long.to_display_text
|
||||
disp.length . should_equal 80
|
||||
disp.characters.take (First 5) . should_equal [ 'H', 'e', 'l', 'l', 'o' ]
|
||||
disp.characters.take (Last 6) . should_equal ['l', 'd', '!', ' ', ' ', '…']
|
||||
disp.characters.take (..First 5) . should_equal [ 'H', 'e', 'l', 'l', 'o' ]
|
||||
disp.characters.take (..Last 6) . should_equal ['l', 'd', '!', ' ', ' ', '…']
|
||||
|
||||
group_builder.specify "grapheme 1 conversion" <|
|
||||
txt = 'a\u0321\u0302'*100
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.Text.Regex.No_Such_Group
|
||||
import Standard.Base.Data.Text.Regex.Regex_Syntax_Error
|
||||
import Standard.Base.Data.Text.Span.Span
|
||||
@ -9,12 +9,8 @@ import Standard.Base.Errors.Common.Missing_Argument
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Base.Data.Text.Text_Sub_Range.Text_Sub_Range import all
|
||||
from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import all
|
||||
|
||||
from Standard.Test import all
|
||||
|
||||
|
||||
type Auto
|
||||
Value a
|
||||
|
||||
@ -374,144 +370,144 @@ add_specs suite_builder =
|
||||
text_2.to_text.should_equal text_2
|
||||
|
||||
group_builder.specify "should allow taking or dropping every other character" <|
|
||||
"ABCDE".take (Every 1) . should_equal "ABCDE"
|
||||
"ABCDE".take (Every 2) . should_equal "ACE"
|
||||
"ABCD".take (Every 2) . should_equal "AC"
|
||||
"ABCD".take (Every 2 first=1) . should_equal "BD"
|
||||
"ABCDE".take (Every 2 first=1) . should_equal "BD"
|
||||
"ABCDE".take (Every 3) . should_equal "AD"
|
||||
"ABCDEFG".take (Every 3) . should_equal "ADG"
|
||||
"ABCDEFG".take (Every 3 first=1) . should_equal "BE"
|
||||
"ABCDEFG".take (Every 3 first=6) . should_equal "G"
|
||||
"ABCDEFG".take (Every 10) . should_equal "A"
|
||||
"ABCDE".take (..Every 1) . should_equal "ABCDE"
|
||||
"ABCDE".take (..Every 2) . should_equal "ACE"
|
||||
"ABCD".take (..Every 2) . should_equal "AC"
|
||||
"ABCD".take (..Every 2 first=1) . should_equal "BD"
|
||||
"ABCDE".take (..Every 2 first=1) . should_equal "BD"
|
||||
"ABCDE".take (..Every 3) . should_equal "AD"
|
||||
"ABCDEFG".take (..Every 3) . should_equal "ADG"
|
||||
"ABCDEFG".take (..Every 3 first=1) . should_equal "BE"
|
||||
"ABCDEFG".take (..Every 3 first=6) . should_equal "G"
|
||||
"ABCDEFG".take (..Every 10) . should_equal "A"
|
||||
|
||||
"ABCDE".drop (Every 1) . should_equal ""
|
||||
"ABCDE".drop (Every 2) . should_equal "BD"
|
||||
"ABCD".drop (Every 2) . should_equal "BD"
|
||||
"ABCD".drop (Every 2 first=1) . should_equal "AC"
|
||||
"ABCDE".drop (Every 2 first=1) . should_equal "ACE"
|
||||
"ABCDE".drop (Every 3) . should_equal "BCE"
|
||||
"ABCDEFG".drop (Every 3) . should_equal "BCEF"
|
||||
"ABCDEFG".drop (Every 3 first=1) . should_equal "ACDFG"
|
||||
"ABCDEFGH".drop (Every 3 first=1) . should_equal "ACDFG"
|
||||
"ABCDEFGHI".drop (Every 3 first=1) . should_equal "ACDFGI"
|
||||
"ABCDE".drop (..Every 1) . should_equal ""
|
||||
"ABCDE".drop (..Every 2) . should_equal "BD"
|
||||
"ABCD".drop (..Every 2) . should_equal "BD"
|
||||
"ABCD".drop (..Every 2 first=1) . should_equal "AC"
|
||||
"ABCDE".drop (..Every 2 first=1) . should_equal "ACE"
|
||||
"ABCDE".drop (..Every 3) . should_equal "BCE"
|
||||
"ABCDEFG".drop (..Every 3) . should_equal "BCEF"
|
||||
"ABCDEFG".drop (..Every 3 first=1) . should_equal "ACDFG"
|
||||
"ABCDEFGH".drop (..Every 3 first=1) . should_equal "ACDFG"
|
||||
"ABCDEFGHI".drop (..Every 3 first=1) . should_equal "ACDFGI"
|
||||
|
||||
group_builder.specify "should allow taking or dropping a random sample of a substring" <|
|
||||
"AAAAA".take (Sample 3) . should_equal "AAA"
|
||||
"AAAAA".drop (Sample 3) . should_equal "AA"
|
||||
"AAAAA".take (..Sample 3) . should_equal "AAA"
|
||||
"AAAAA".drop (..Sample 3) . should_equal "AA"
|
||||
|
||||
## These tests are very brittle and can be invalidated by a valid
|
||||
implementation modification, so they may need to be updated.
|
||||
"ABCDEFGH".take (Sample 0) . should_equal ""
|
||||
"ABCDEFGH".take (Sample 8 seed=42) . should_equal "FGCHABED"
|
||||
"ABCDEFGH".take (Sample 4 seed=42) . should_equal "FGCH"
|
||||
"ABCDEFGH".take (Sample 2 seed=42) . should_equal "FG"
|
||||
"ABCDEFGH".take (Sample 1 seed=42) . should_equal "F"
|
||||
"ABCDEFGH".take (Sample 100 seed=42) . should_equal "FGCHABED"
|
||||
"ABCDEFGH".take (..Sample 0) . should_equal ""
|
||||
"ABCDEFGH".take (..Sample 8 seed=42) . should_equal "FGCHABED"
|
||||
"ABCDEFGH".take (..Sample 4 seed=42) . should_equal "FGCH"
|
||||
"ABCDEFGH".take (..Sample 2 seed=42) . should_equal "FG"
|
||||
"ABCDEFGH".take (..Sample 1 seed=42) . should_equal "F"
|
||||
"ABCDEFGH".take (..Sample 100 seed=42) . should_equal "FGCHABED"
|
||||
|
||||
samples_1 = 0.up_to 10000 . map seed->
|
||||
"ABCD".take (Sample 2 seed)
|
||||
"ABCD".take (..Sample 2 seed)
|
||||
samples_1.should_contain_the_same_elements_as ["AB", "BA", "AC", "CA", "AD", "DA", "BC", "CB", "BD", "DB", "CD", "DC"]
|
||||
|
||||
"ABCDEFGH".drop (Sample 0) . should_equal "ABCDEFGH"
|
||||
"ABCDEFGH".drop (Sample 1 seed=42) . should_equal "ABCDEGH"
|
||||
"ABCDEFGH".drop (Sample 2 seed=42) . should_equal "ABCDEH"
|
||||
"ABCDEFGH".drop (Sample 4 seed=42) . should_equal "ABDE"
|
||||
"ABCDEFGH".drop (Sample 8 seed=42) . should_equal ""
|
||||
"ABCDEFGH".drop (Sample 100 seed=42) . should_equal ""
|
||||
"ABCDEFGH".drop (..Sample 0) . should_equal "ABCDEFGH"
|
||||
"ABCDEFGH".drop (..Sample 1 seed=42) . should_equal "ABCDEGH"
|
||||
"ABCDEFGH".drop (..Sample 2 seed=42) . should_equal "ABCDEH"
|
||||
"ABCDEFGH".drop (..Sample 4 seed=42) . should_equal "ABDE"
|
||||
"ABCDEFGH".drop (..Sample 8 seed=42) . should_equal ""
|
||||
"ABCDEFGH".drop (..Sample 100 seed=42) . should_equal ""
|
||||
|
||||
samples_2 = 0.up_to 10000 . map seed->
|
||||
"ABCD".drop (Sample 2 seed)
|
||||
"ABCD".drop (..Sample 2 seed)
|
||||
samples_2.should_contain_the_same_elements_as ["AB", "AC", "AD", "BC", "CD", "BD"]
|
||||
|
||||
group_builder.specify "should allow taking or dropping many indices or subranges (possibly overlapping)" <|
|
||||
"123"*1000 . take (By_Index (Vector.new 3000 ix-> 2999-ix)) . should_equal "321"*1000
|
||||
"123"*1000 . take (By_Index (Vector.new 3000 _-> 0)) . should_equal "1"*3000
|
||||
"123456"*1000 . take (By_Index (Vector.new 100 ix-> Range.Between 6*ix+1 6*ix+3)) . should_equal "23"*100
|
||||
"AB"*1000 . take (By_Index (Vector.new 100 ix-> Range.Between ix+1 ix+5)) . should_equal "BABAABAB"*50
|
||||
"123"*1000 . take (..By_Index (Vector.new 3000 ix-> 2999-ix)) . should_equal "321"*1000
|
||||
"123"*1000 . take (..By_Index (Vector.new 3000 _-> 0)) . should_equal "1"*3000
|
||||
"123456"*1000 . take (..By_Index (Vector.new 100 ix-> Range.Between 6*ix+1 6*ix+3)) . should_equal "23"*100
|
||||
"AB"*1000 . take (..By_Index (Vector.new 100 ix-> Range.Between ix+1 ix+5)) . should_equal "BABAABAB"*50
|
||||
|
||||
"123"*1000 . drop (By_Index (Vector.new 300 ix-> 2999-ix)) . should_equal "123"*900
|
||||
"123"*1000 . drop (By_Index (Vector.new 3000 _-> 0)) . should_equal "23"+"123"*999
|
||||
"123456"*1000 . drop (By_Index (Vector.new 1000 ix-> Range.Between 6*ix+1 6*ix+3)) . should_equal "1456"*1000
|
||||
"ABCD"*25 . drop (By_Index (Vector.new 90 ix-> Range.Between ix+1 ix+5)) . should_equal "ACDABCD"
|
||||
"123"*1000 . drop (..By_Index (Vector.new 300 ix-> 2999-ix)) . should_equal "123"*900
|
||||
"123"*1000 . drop (..By_Index (Vector.new 3000 _-> 0)) . should_equal "23"+"123"*999
|
||||
"123456"*1000 . drop (..By_Index (Vector.new 1000 ix-> Range.Between 6*ix+1 6*ix+3)) . should_equal "1456"*1000
|
||||
"ABCD"*25 . drop (..By_Index (Vector.new 90 ix-> Range.Between ix+1 ix+5)) . should_equal "ACDABCD"
|
||||
|
||||
"ABCD"*1000 . take (0.up_to 4000 . with_step 4) . should_equal "A"*1000
|
||||
"ABCD"*1000 . take (Every 4) . should_equal "A"*1000
|
||||
"ABCD"*1000 . take (By_Index [0.up_to 4000 . with_step 4, 1.up_to 4000 . with_step 4]) . should_equal ("A"*1000 + "B"*1000)
|
||||
"ABCD"*1000 . take (By_Index [0.up_to 4000 . with_step 4, 2.up_to 4000 . with_step 4]) . should_equal ("A"*1000 + "C"*1000)
|
||||
"ABCD"*1000 . take (..Every 4) . should_equal "A"*1000
|
||||
"ABCD"*1000 . take (..By_Index [0.up_to 4000 . with_step 4, 1.up_to 4000 . with_step 4]) . should_equal ("A"*1000 + "B"*1000)
|
||||
"ABCD"*1000 . take (..By_Index [0.up_to 4000 . with_step 4, 2.up_to 4000 . with_step 4]) . should_equal ("A"*1000 + "C"*1000)
|
||||
|
||||
"ABCD"*1000 . drop (0.up_to 4000 . with_step 4) . should_equal "BCD"*1000
|
||||
"ABCD"*1000 . drop (Every 4) . should_equal "BCD"*1000
|
||||
"ABCD"*1000 . drop (By_Index [0.up_to 4000 . with_step 4, 1.up_to 4000 . with_step 4]) . should_equal "CD"*1000
|
||||
"ABCD"*1000 . drop (By_Index [0.up_to 4000 . with_step 4, 2.up_to 4000 . with_step 4]) . should_equal "BD"*1000
|
||||
"ABCD"*1000 . drop (..Every 4) . should_equal "BCD"*1000
|
||||
"ABCD"*1000 . drop (..By_Index [0.up_to 4000 . with_step 4, 1.up_to 4000 . with_step 4]) . should_equal "CD"*1000
|
||||
"ABCD"*1000 . drop (..By_Index [0.up_to 4000 . with_step 4, 2.up_to 4000 . with_step 4]) . should_equal "BD"*1000
|
||||
|
||||
"0123456789".take (By_Index [0.up_to 4, 4.up_to 6, 8.up_to 9]) . should_equal "0123458"
|
||||
"0123456789".take (By_Index [4.up_to 6, 0.up_to 4, 0, 0]) . should_equal "45012300"
|
||||
"0123456789".drop (By_Index [0.up_to 4, 4.up_to 6, 8.up_to 9]) . should_equal "679"
|
||||
"0123456789".drop (By_Index [4.up_to 6, 0.up_to 4, 0, 0]) . should_equal "6789"
|
||||
"0123456789".drop (By_Index [2.up_to 5, 0.up_to 3, 0, 0]) . should_equal "56789"
|
||||
"0123456789".take (..By_Index [0.up_to 4, 4.up_to 6, 8.up_to 9]) . should_equal "0123458"
|
||||
"0123456789".take (..By_Index [4.up_to 6, 0.up_to 4, 0, 0]) . should_equal "45012300"
|
||||
"0123456789".drop (..By_Index [0.up_to 4, 4.up_to 6, 8.up_to 9]) . should_equal "679"
|
||||
"0123456789".drop (..By_Index [4.up_to 6, 0.up_to 4, 0, 0]) . should_equal "6789"
|
||||
"0123456789".drop (..By_Index [2.up_to 5, 0.up_to 3, 0, 0]) . should_equal "56789"
|
||||
|
||||
group_builder.specify "should allow selecting substrings by characters" <|
|
||||
txt = kshi + facepalm + accent_1 + accent_2
|
||||
txt.take (First 2) . should_equal (kshi + facepalm)
|
||||
txt.drop (First 2) . should_equal (accent_1 + accent_2)
|
||||
txt.take (..First 2) . should_equal (kshi + facepalm)
|
||||
txt.drop (..First 2) . should_equal (accent_1 + accent_2)
|
||||
txt.take 2 . should_equal (kshi + facepalm)
|
||||
txt.drop 2 . should_equal (accent_1 + accent_2)
|
||||
txt.take (Last 2) . should_equal (accent_1 + accent_2)
|
||||
txt.drop (Last 2) . should_equal (kshi + facepalm)
|
||||
txt.take (..Last 2) . should_equal (accent_1 + accent_2)
|
||||
txt.drop (..Last 2) . should_equal (kshi + facepalm)
|
||||
txt.take (0.up_to 2) . should_equal (kshi + facepalm)
|
||||
txt.take (By_Index (0.up_to 2)) . should_equal (kshi + facepalm)
|
||||
txt.take (..By_Index (0.up_to 2)) . should_equal (kshi + facepalm)
|
||||
txt.drop (0.up_to 2) . should_equal (accent_1 + accent_2)
|
||||
txt.take (2.up_to 4) . should_equal (accent_1 + accent_2)
|
||||
txt.drop (2.up_to 4) . should_equal (kshi + facepalm)
|
||||
txt.take (Every 2) . should_equal (kshi + accent_1)
|
||||
txt.take (Every 2 first=1) . should_equal (facepalm + accent_2)
|
||||
txt.drop (Every 2) . should_equal (facepalm + accent_2)
|
||||
txt.take (..Every 2) . should_equal (kshi + accent_1)
|
||||
txt.take (..Every 2 first=1) . should_equal (facepalm + accent_2)
|
||||
txt.drop (..Every 2) . should_equal (facepalm + accent_2)
|
||||
txt.take (0.up_to 4 . with_step 2) . should_equal (kshi + accent_1)
|
||||
txt.take (By_Index [0, 3]) . should_equal (kshi + accent_2)
|
||||
txt.take (By_Index 0) . should_equal kshi
|
||||
txt.take (By_Index 1) . should_equal facepalm
|
||||
txt.take (By_Index 2) . should_equal accent_1
|
||||
txt.take (By_Index 3) . should_equal accent_2
|
||||
txt.drop (By_Index [0, 3]) . should_equal (facepalm + accent_1)
|
||||
txt.drop (By_Index [0, 3, 0]) . should_equal (facepalm + accent_1)
|
||||
txt.drop (By_Index [0, 3, 0, 2, 1]) . should_equal ""
|
||||
txt.take (By_Index [0, 3, 0, 2, 1]) . should_equal (kshi + accent_2 + kshi + accent_1 + facepalm)
|
||||
txt.take (By_Index [0, 0, 0.up_to 2]) . should_equal (kshi + kshi + kshi + facepalm)
|
||||
txt.drop (By_Index [2.up_to 4, 0.up_to 2]) . should_equal ""
|
||||
txt.take (..By_Index [0, 3]) . should_equal (kshi + accent_2)
|
||||
txt.take (..By_Index 0) . should_equal kshi
|
||||
txt.take (..By_Index 1) . should_equal facepalm
|
||||
txt.take (..By_Index 2) . should_equal accent_1
|
||||
txt.take (..By_Index 3) . should_equal accent_2
|
||||
txt.drop (..By_Index [0, 3]) . should_equal (facepalm + accent_1)
|
||||
txt.drop (..By_Index [0, 3, 0]) . should_equal (facepalm + accent_1)
|
||||
txt.drop (..By_Index [0, 3, 0, 2, 1]) . should_equal ""
|
||||
txt.take (..By_Index [0, 3, 0, 2, 1]) . should_equal (kshi + accent_2 + kshi + accent_1 + facepalm)
|
||||
txt.take (..By_Index [0, 0, 0.up_to 2]) . should_equal (kshi + kshi + kshi + facepalm)
|
||||
txt.drop (..By_Index [2.up_to 4, 0.up_to 2]) . should_equal ""
|
||||
|
||||
group_builder.specify "take should work as in the examples" <|
|
||||
"Hello World!".take First . should_equal "H"
|
||||
"Hello World!".take (First 5) . should_equal "Hello"
|
||||
"Hello World!".take (First 100) . should_equal "Hello World!"
|
||||
"Hello World!".take (First 0) . should_equal ""
|
||||
"Hello World!".take ..First . should_equal "H"
|
||||
"Hello World!".take (..First 5) . should_equal "Hello"
|
||||
"Hello World!".take (..First 100) . should_equal "Hello World!"
|
||||
"Hello World!".take (..First 0) . should_equal ""
|
||||
"Hello World!".take . should_equal "H"
|
||||
"Hello World!".take 5 . should_equal "Hello"
|
||||
"Hello World!".take 100 . should_equal "Hello World!"
|
||||
"Hello World!".take 0 . should_equal ""
|
||||
"Hello World!".take Last . should_equal "!"
|
||||
"Hello World!".take (Last 6) . should_equal "World!"
|
||||
"Hello World!".take (Last 0) . should_equal ""
|
||||
"Hello World!".take (Last 100) . should_equal "Hello World!"
|
||||
"Hello World!".take (Before " ") . should_equal "Hello"
|
||||
"Hello World!".take (Before "z") . should_equal "Hello World!"
|
||||
"Hello World!".take (Before_Last "o") . should_equal "Hello W"
|
||||
"Hello World!".take (Before_Last "z") . should_equal "Hello World!"
|
||||
"Hello World!".take (After " ") . should_equal "World!"
|
||||
"Hello World!".take (After "z") . should_equal ""
|
||||
"Hello World!".take (After_Last "o") . should_equal "rld!"
|
||||
"Hello World!".take (After_Last "z") . should_equal ""
|
||||
"Hello World!".take (While c->c!=" ") . should_equal "Hello"
|
||||
"Hello World!".take (While c->c!="z") . should_equal "Hello World!"
|
||||
"Hello World!".take ..Last . should_equal "!"
|
||||
"Hello World!".take (..Last 6) . should_equal "World!"
|
||||
"Hello World!".take (..Last 0) . should_equal ""
|
||||
"Hello World!".take (..Last 100) . should_equal "Hello World!"
|
||||
"Hello World!".take (..Before " ") . should_equal "Hello"
|
||||
"Hello World!".take (..Before "z") . should_equal "Hello World!"
|
||||
"Hello World!".take (..Before_Last "o") . should_equal "Hello W"
|
||||
"Hello World!".take (..Before_Last "z") . should_equal "Hello World!"
|
||||
"Hello World!".take (..After " ") . should_equal "World!"
|
||||
"Hello World!".take (..After "z") . should_equal ""
|
||||
"Hello World!".take (..After_Last "o") . should_equal "rld!"
|
||||
"Hello World!".take (..After_Last "z") . should_equal ""
|
||||
"Hello World!".take (..While c->c!=" ") . should_equal "Hello"
|
||||
"Hello World!".take (..While c->c!="z") . should_equal "Hello World!"
|
||||
"Hello World!".take (3.up_to 5) . should_equal "lo"
|
||||
"Hello World!".take (5.up_to 12) . should_equal " World!"
|
||||
"Hello World!".take (6.up_to 12 . with_step 2) . should_equal "Wrd"
|
||||
"Hello World!".take (Every 2 first=6) . should_equal "Wrd"
|
||||
"Hello World!".take (Every 3) . should_equal "HlWl"
|
||||
"Hello World!".take (By_Index 0) . should_equal "H"
|
||||
"Hello World!".take (By_Index [1, 0, 0, 6, 0]) . should_equal "eHHWH"
|
||||
"Hello World!".take (By_Index [0.up_to 3, 6, 6.up_to 12 . with_step 2]) . should_equal "HelWWrd"
|
||||
"Hello World!".take (Sample 3 seed=42) . should_equal "l d"
|
||||
"Hello World!".take (..Every 2 first=6) . should_equal "Wrd"
|
||||
"Hello World!".take (..Every 3) . should_equal "HlWl"
|
||||
"Hello World!".take (..By_Index 0) . should_equal "H"
|
||||
"Hello World!".take (..By_Index [1, 0, 0, 6, 0]) . should_equal "eHHWH"
|
||||
"Hello World!".take (..By_Index [0.up_to 3, 6, 6.up_to 12 . with_step 2]) . should_equal "HelWWrd"
|
||||
"Hello World!".take (..Sample 3 seed=42) . should_equal "l d"
|
||||
|
||||
group_builder.specify "take should report errors for start indices out of bounds but just go till the end if the end index is OOB" <|
|
||||
txt = "Hello World!"
|
||||
@ -521,248 +517,248 @@ add_specs suite_builder =
|
||||
txt.take (Range.Between txt.length txt.length) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (Range.Between txt.length txt.length) . catch . should_equal (Index_Out_Of_Bounds.Error txt.length txt.length)
|
||||
txt.take (Range.Between txt.length 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (First 100) . should_equal txt
|
||||
txt.take (..First 100) . should_equal txt
|
||||
txt.take 100 . should_equal txt
|
||||
txt.take (Last 100) . should_equal txt
|
||||
txt.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 1, 6.up_to 100]) . should_equal "HeWorld!"
|
||||
txt.take (By_Index [0, 1, 6.up_to 100 . with_step 2]) . should_equal "HeWrd"
|
||||
txt.take (..Last 100) . should_equal txt
|
||||
txt.take (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0, 1, 6.up_to 100]) . should_equal "HeWorld!"
|
||||
txt.take (..By_Index [0, 1, 6.up_to 100 . with_step 2]) . should_equal "HeWrd"
|
||||
txt.take (13.up_to 12) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"ABC".take (By_Index 3) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"ABC".take (..By_Index 3) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (13.up_to 20) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (13.up_to 20 . with_step 2) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 2, 13.up_to 20]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 0, 13.up_to 10, 2.up_to 2 . with_step 2]) . should_equal ""
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . catch . should_equal (Index_Out_Of_Bounds.Error 13 12)
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, txt.length.up_to 100 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0.up_to 2, 13.up_to 20]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0.up_to 0, 13.up_to 10, 2.up_to 2 . with_step 2]) . should_equal ""
|
||||
txt.take (..By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (..By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . catch . should_equal (Index_Out_Of_Bounds.Error 13 12)
|
||||
txt.take (..By_Index [0.up_to 2 . with_step 2, txt.length.up_to 100 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
group_builder.specify "take should work on grapheme clusters" <|
|
||||
txt_1 = 'He\u0302llo\u0308 Wo\u0301rld!'
|
||||
txt_2 = 'He\u0302llo\u0308 Wo\u0308rld!'
|
||||
txt_1.take (Every 2) . should_equal 'Hlo\u0308Wrd'
|
||||
txt_1.take (First 2) . should_equal 'He\u{302}'
|
||||
txt_1.take (First 5) . should_equal 'He\u{302}llo\u{308}'
|
||||
txt_1.take (..Every 2) . should_equal 'Hlo\u0308Wrd'
|
||||
txt_1.take (..First 2) . should_equal 'He\u{302}'
|
||||
txt_1.take (..First 5) . should_equal 'He\u{302}llo\u{308}'
|
||||
txt_1.take 2 . should_equal 'He\u{302}'
|
||||
txt_1.take 5 . should_equal 'He\u{302}llo\u{308}'
|
||||
txt_1.take (Last 6) . should_equal 'Wo\u{301}rld!'
|
||||
txt_1.take (Last 5) . should_equal 'o\u{301}rld!'
|
||||
txt_1.take (Before 'e\u{302}') . should_equal 'H'
|
||||
txt_1.take (Before 'ê') . should_equal 'H'
|
||||
txt_1.take (Before 'e') . should_equal txt_1
|
||||
txt_2.take (Before_Last 'o\u{308}') . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_2.take (Before_Last 'ö') . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_2.take (Before_Last 'o') . should_equal txt_2
|
||||
txt_1.take (After 'e\u{302}') . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.take (After 'ê') . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.take (After 'e\u{308}') . should_equal ''
|
||||
txt_1.take (After 'e') . should_equal ''
|
||||
txt_2.take (After_Last 'o\u{308}') . should_equal 'rld!'
|
||||
txt_2.take (After_Last 'ö') . should_equal 'rld!'
|
||||
txt_2.take (After_Last 'o') . should_equal ''
|
||||
txt_2.take (While c->c!='e\u{302}') . should_equal 'H'
|
||||
txt_2.take (While c->c!='ê') . should_equal 'H'
|
||||
txt_2.take (While c->c!='e') . should_equal txt_2
|
||||
txt_1.take (..Last 6) . should_equal 'Wo\u{301}rld!'
|
||||
txt_1.take (..Last 5) . should_equal 'o\u{301}rld!'
|
||||
txt_1.take (..Before 'e\u{302}') . should_equal 'H'
|
||||
txt_1.take (..Before 'ê') . should_equal 'H'
|
||||
txt_1.take (..Before 'e') . should_equal txt_1
|
||||
txt_2.take (..Before_Last 'o\u{308}') . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_2.take (..Before_Last 'ö') . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_2.take (..Before_Last 'o') . should_equal txt_2
|
||||
txt_1.take (..After 'e\u{302}') . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.take (..After 'ê') . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.take (..After 'e\u{308}') . should_equal ''
|
||||
txt_1.take (..After 'e') . should_equal ''
|
||||
txt_2.take (..After_Last 'o\u{308}') . should_equal 'rld!'
|
||||
txt_2.take (..After_Last 'ö') . should_equal 'rld!'
|
||||
txt_2.take (..After_Last 'o') . should_equal ''
|
||||
txt_2.take (..While c->c!='e\u{302}') . should_equal 'H'
|
||||
txt_2.take (..While c->c!='ê') . should_equal 'H'
|
||||
txt_2.take (..While c->c!='e') . should_equal txt_2
|
||||
txt_2.take (3.up_to 5) . should_equal 'lo\u{308}'
|
||||
txt_2.take (5.up_to 12) . should_equal ' Wo\u{308}rld!'
|
||||
|
||||
group_builder.specify "take should work on emojis" <|
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take First . should_equal '✨'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (First 2) . should_equal '✨🚀'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take ..First . should_equal '✨'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (..First 2) . should_equal '✨🚀'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take . should_equal '✨'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take 2 . should_equal '✨🚀'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take Last . should_equal '☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (Last 0) . should_equal ''
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (Last 3) . should_equal '😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (Before '😍') . should_equal '✨🚀🚧'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (Before_Last '😍') . should_equal '✨🚀🚧😍😃'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (After '😍') . should_equal '😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (After_Last '😍') . should_equal '😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (While c->c!="😃") . should_equal '✨🚀🚧😍'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take ..Last . should_equal '☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (..Last 0) . should_equal ''
|
||||
'✨🚀🚧😍😃😎😙😉☺'.take (..Last 3) . should_equal '😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (..Before '😍') . should_equal '✨🚀🚧'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (..Before_Last '😍') . should_equal '✨🚀🚧😍😃'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (..After '😍') . should_equal '😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (..After_Last '😍') . should_equal '😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (..While c->c!="😃") . should_equal '✨🚀🚧😍'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.take (3.up_to 6) . should_equal '😍😃😍'
|
||||
|
||||
group_builder.specify "take should correctly handle edge cases" <|
|
||||
"ABC".take . should_equal "A"
|
||||
|
||||
"".take First . should_equal ""
|
||||
"".take Last . should_equal ""
|
||||
"".take ..First . should_equal ""
|
||||
"".take ..Last . should_equal ""
|
||||
|
||||
"".take (After "a") . should_equal ""
|
||||
"".take (After_Last "a") . should_equal ""
|
||||
"".take (Before "a") . should_equal ""
|
||||
"".take (Before_Last "a") . should_equal ""
|
||||
"".take (..After "a") . should_equal ""
|
||||
"".take (..After_Last "a") . should_equal ""
|
||||
"".take (..Before "a") . should_equal ""
|
||||
"".take (..Before_Last "a") . should_equal ""
|
||||
|
||||
"".take (After "") . should_equal ""
|
||||
"".take (After_Last "") . should_equal ""
|
||||
"".take (Before "") . should_equal ""
|
||||
"".take (Before_Last "") . should_equal ""
|
||||
"".take (..After "") . should_equal ""
|
||||
"".take (..After_Last "") . should_equal ""
|
||||
"".take (..Before "") . should_equal ""
|
||||
"".take (..Before_Last "") . should_equal ""
|
||||
|
||||
"".take (While _->True) . should_equal ""
|
||||
"".take (..While _->True) . should_equal ""
|
||||
|
||||
'ABC\u{301}'.take (0.up_to 0) . should_equal ""
|
||||
|
||||
'ABC\u{301}'.take (After "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.take (After_Last "") . should_equal ""
|
||||
'ABC\u{301}'.take (Before "") . should_equal ""
|
||||
'ABC\u{301}'.take (Before_Last "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.take (..After "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.take (..After_Last "") . should_equal ""
|
||||
'ABC\u{301}'.take (..Before "") . should_equal ""
|
||||
'ABC\u{301}'.take (..Before_Last "") . should_equal 'ABC\u{301}'
|
||||
|
||||
"ABC".take (By_Index -1) . should_equal "C"
|
||||
"ABC".take (By_Index [-1, -1, -1, -3, 2]) . should_equal "CCCAC"
|
||||
"ABC".take (By_Index []) . should_equal ""
|
||||
"ABC".take (By_Index ((-2).up_to -1)) . should_fail_with Illegal_Argument
|
||||
"".take (Every 2) . should_equal ""
|
||||
"".take (Every 2 first=1) . should_equal ""
|
||||
"ABC".take (Every 5) . should_equal "A"
|
||||
"A".take (Every 5) . should_equal "A"
|
||||
"ABC".take (Every 5 first=4) . should_equal ""
|
||||
"".take (Sample 0) . should_equal ""
|
||||
"".take (Sample 100) . should_equal ""
|
||||
"ABC".take (..By_Index -1) . should_equal "C"
|
||||
"ABC".take (..By_Index [-1, -1, -1, -3, 2]) . should_equal "CCCAC"
|
||||
"ABC".take (..By_Index []) . should_equal ""
|
||||
"ABC".take (..By_Index ((-2).up_to -1)) . should_fail_with Illegal_Argument
|
||||
"".take (..Every 2) . should_equal ""
|
||||
"".take (..Every 2 first=1) . should_equal ""
|
||||
"ABC".take (..Every 5) . should_equal "A"
|
||||
"A".take (..Every 5) . should_equal "A"
|
||||
"ABC".take (..Every 5 first=4) . should_equal ""
|
||||
"".take (..Sample 0) . should_equal ""
|
||||
"".take (..Sample 100) . should_equal ""
|
||||
|
||||
group_builder.specify "drop should work as in the examples" <|
|
||||
"Hello World!".drop First . should_equal "ello World!"
|
||||
"Hello World!".drop (First 5) . should_equal " World!"
|
||||
"Hello World!".drop (First 100) . should_equal ""
|
||||
"Hello World!".drop (First 0) . should_equal "Hello World!"
|
||||
"Hello World!".drop ..First . should_equal "ello World!"
|
||||
"Hello World!".drop (..First 5) . should_equal " World!"
|
||||
"Hello World!".drop (..First 100) . should_equal ""
|
||||
"Hello World!".drop (..First 0) . should_equal "Hello World!"
|
||||
"Hello World!".drop . should_equal "ello World!"
|
||||
"Hello World!".drop 5 . should_equal " World!"
|
||||
"Hello World!".drop 100 . should_equal ""
|
||||
"Hello World!".drop 0 . should_equal "Hello World!"
|
||||
"Hello World!".drop Last . should_equal "Hello World"
|
||||
"Hello World!".drop (Last 6) . should_equal "Hello "
|
||||
"Hello World!".drop (Last 100) . should_equal ""
|
||||
"Hello World!".drop (Before " ") . should_equal " World!"
|
||||
"Hello World!".drop (Before "z") . should_equal ""
|
||||
"Hello World!".drop (Before_Last "o") . should_equal "orld!"
|
||||
"Hello World!".drop (Before_Last "z") . should_equal ""
|
||||
"Hello World!".drop (After " ") . should_equal "Hello "
|
||||
"Hello World!".drop (After "z") . should_equal "Hello World!"
|
||||
"Hello World!".drop (After_Last "o") . should_equal "Hello Wo"
|
||||
"Hello World!".drop (After_Last "z") . should_equal "Hello World!"
|
||||
"Hello World!".drop (While c->c!=" ") . should_equal " World!"
|
||||
"Hello World!".drop (While c->c!="z") . should_equal ""
|
||||
"Hello World!".drop ..Last . should_equal "Hello World"
|
||||
"Hello World!".drop (..Last 6) . should_equal "Hello "
|
||||
"Hello World!".drop (..Last 100) . should_equal ""
|
||||
"Hello World!".drop (..Before " ") . should_equal " World!"
|
||||
"Hello World!".drop (..Before "z") . should_equal ""
|
||||
"Hello World!".drop (..Before_Last "o") . should_equal "orld!"
|
||||
"Hello World!".drop (..Before_Last "z") . should_equal ""
|
||||
"Hello World!".drop (..After " ") . should_equal "Hello "
|
||||
"Hello World!".drop (..After "z") . should_equal "Hello World!"
|
||||
"Hello World!".drop (..After_Last "o") . should_equal "Hello Wo"
|
||||
"Hello World!".drop (..After_Last "z") . should_equal "Hello World!"
|
||||
"Hello World!".drop (..While c->c!=" ") . should_equal " World!"
|
||||
"Hello World!".drop (..While c->c!="z") . should_equal ""
|
||||
"Hello World!".drop (3.up_to 5) . should_equal "Hel World!"
|
||||
"Hello World!".drop (5.up_to 12) . should_equal "Hello"
|
||||
"Hello World!".drop (6.up_to 12 . with_step 2) . should_equal "Hello ol!"
|
||||
"Hello World!".drop (Every 2 first=6) . should_equal "Hello ol!"
|
||||
"Hello World!".drop (Every 3) . should_equal "elo ord!"
|
||||
"Hello World!".drop (By_Index 0) . should_equal "ello World!"
|
||||
"Hello World!".drop (By_Index [1, 0, 0, 6, 0]) . should_equal "llo orld!"
|
||||
"Hello World!".drop (By_Index [0.up_to 3, 6, 6.up_to 12 . with_step 2]) . should_equal "lo ol!"
|
||||
"Hello World!".drop (Sample 3 seed=42) . should_equal "HeloWorl!"
|
||||
"Hello World!".drop (..Every 2 first=6) . should_equal "Hello ol!"
|
||||
"Hello World!".drop (..Every 3) . should_equal "elo ord!"
|
||||
"Hello World!".drop (..By_Index 0) . should_equal "ello World!"
|
||||
"Hello World!".drop (..By_Index [1, 0, 0, 6, 0]) . should_equal "llo orld!"
|
||||
"Hello World!".drop (..By_Index [0.up_to 3, 6, 6.up_to 12 . with_step 2]) . should_equal "lo ol!"
|
||||
"Hello World!".drop (..Sample 3 seed=42) . should_equal "HeloWorl!"
|
||||
|
||||
group_builder.specify "drop should report errors for start indices out of bounds but just go till the end if the end index is OOB" <|
|
||||
txt = "Hello World!"
|
||||
txt.drop (0.up_to 14) . should_equal ""
|
||||
txt.drop (First 100) . should_equal ""
|
||||
txt.drop (..First 100) . should_equal ""
|
||||
txt.drop 100 . should_equal ""
|
||||
txt.drop (Last 100) . should_equal ""
|
||||
txt.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 12)
|
||||
txt.drop (By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 1, 6.up_to 100]) . should_equal "llo "
|
||||
txt.drop (..Last 100) . should_equal ""
|
||||
txt.drop (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (..By_Index 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 12)
|
||||
txt.drop (..By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (..By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (..By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (..By_Index [0, 1, 6.up_to 100]) . should_equal "llo "
|
||||
txt.drop (13.up_to 12) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (14.up_to 15) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
txt.drop (0.up_to 0) . should_equal txt
|
||||
txt.drop (5.up_to 100) . should_equal "Hello"
|
||||
txt.drop (5.up_to 100 . with_step 2) . should_equal "HelloWrd"
|
||||
txt.drop (By_Index [0, 1, 0, 5.up_to 100 . with_step 2]) . should_equal "lloWrd"
|
||||
txt.drop (..By_Index [0, 1, 0, 5.up_to 100 . with_step 2]) . should_equal "lloWrd"
|
||||
|
||||
group_builder.specify "drop should work on grapheme clusters" <|
|
||||
txt_1 = 'He\u0302llo\u0308 Wo\u0301rld!'
|
||||
txt_2 = 'He\u0302llo\u0308 Wo\u0308rld!'
|
||||
txt_1.drop (Every 2) . should_equal 'e\u0302l o\u0301l!'
|
||||
txt_1.drop (First 2) . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (First 5) . should_equal ' Wo\u{301}rld!'
|
||||
txt_1.drop (..Every 2) . should_equal 'e\u0302l o\u0301l!'
|
||||
txt_1.drop (..First 2) . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (..First 5) . should_equal ' Wo\u{301}rld!'
|
||||
txt_1.drop 2 . should_equal 'llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop 5 . should_equal ' Wo\u{301}rld!'
|
||||
txt_1.drop (Last 6) . should_equal 'He\u{302}llo\u{308} '
|
||||
txt_1.drop (Last 5) . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_1.drop (Before 'e\u{302}') . should_equal 'e\u{302}llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (Before 'ê') . should_equal 'e\u{302}llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (Before 'e') . should_equal ''
|
||||
txt_2.drop (Before_Last 'o\u{308}') . should_equal 'o\u{308}rld!'
|
||||
txt_2.drop (Before_Last 'ö') . should_equal 'o\u{308}rld!'
|
||||
txt_2.drop (Before_Last 'o') . should_equal ''
|
||||
txt_1.drop (After 'e\u{302}') . should_equal 'He\u{302}'
|
||||
txt_1.drop (After 'ê') . should_equal 'He\u{302}'
|
||||
txt_1.drop (After 'e\u{308}') . should_equal txt_1
|
||||
txt_1.drop (After 'e') . should_equal txt_1
|
||||
txt_2.drop (After_Last 'o\u{308}') . should_equal 'He\u{302}llo\u{308} Wo\u{308}'
|
||||
txt_2.drop (After_Last 'ö') . should_equal 'He\u{302}llo\u{308} Wo\u{308}'
|
||||
txt_2.drop (After_Last 'o') . should_equal txt_2
|
||||
txt_2.drop (While c->c!='e\u{302}') . should_equal 'e\u{302}llo\u{308} Wo\u{308}rld!'
|
||||
txt_2.drop (While c->c!='ê') . should_equal 'e\u{302}llo\u{308} Wo\u{308}rld!'
|
||||
txt_2.drop (While c->c!='e') . should_equal ''
|
||||
txt_1.drop (..Last 6) . should_equal 'He\u{302}llo\u{308} '
|
||||
txt_1.drop (..Last 5) . should_equal 'He\u{302}llo\u{308} W'
|
||||
txt_1.drop (..Before 'e\u{302}') . should_equal 'e\u{302}llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (..Before 'ê') . should_equal 'e\u{302}llo\u{308} Wo\u{301}rld!'
|
||||
txt_1.drop (..Before 'e') . should_equal ''
|
||||
txt_2.drop (..Before_Last 'o\u{308}') . should_equal 'o\u{308}rld!'
|
||||
txt_2.drop (..Before_Last 'ö') . should_equal 'o\u{308}rld!'
|
||||
txt_2.drop (..Before_Last 'o') . should_equal ''
|
||||
txt_1.drop (..After 'e\u{302}') . should_equal 'He\u{302}'
|
||||
txt_1.drop (..After 'ê') . should_equal 'He\u{302}'
|
||||
txt_1.drop (..After 'e\u{308}') . should_equal txt_1
|
||||
txt_1.drop (..After 'e') . should_equal txt_1
|
||||
txt_2.drop (..After_Last 'o\u{308}') . should_equal 'He\u{302}llo\u{308} Wo\u{308}'
|
||||
txt_2.drop (..After_Last 'ö') . should_equal 'He\u{302}llo\u{308} Wo\u{308}'
|
||||
txt_2.drop (..After_Last 'o') . should_equal txt_2
|
||||
txt_2.drop (..While c->c!='e\u{302}') . should_equal 'e\u{302}llo\u{308} Wo\u{308}rld!'
|
||||
txt_2.drop (..While c->c!='ê') . should_equal 'e\u{302}llo\u{308} Wo\u{308}rld!'
|
||||
txt_2.drop (..While c->c!='e') . should_equal ''
|
||||
txt_2.drop (3.up_to 5) . should_equal 'He\u{302}l Wo\u{308}rld!'
|
||||
txt_2.drop (5.up_to 12) . should_equal 'He\u{302}llo\u{308}'
|
||||
|
||||
group_builder.specify "drop should work on emojis" <|
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop First . should_equal '🚀🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop (First 2) . should_equal '🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop ..First . should_equal '🚀🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop (..First 2) . should_equal '🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop . should_equal '🚀🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop 2 . should_equal '🚧😍😃😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop Last . should_equal '✨🚀🚧😍😃😎😙😉'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop (Last 3) . should_equal '✨🚀🚧😍😃😎'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Before '😍') . should_equal '😍😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (Before_Last '😍') . should_equal '😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (After '😍') . should_equal '✨🚀🚧😍'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (After_Last '😍') . should_equal '✨🚀🚧😍😃😍'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (While c->c!="😃") . should_equal '😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop ..Last . should_equal '✨🚀🚧😍😃😎😙😉'
|
||||
'✨🚀🚧😍😃😎😙😉☺'.drop (..Last 3) . should_equal '✨🚀🚧😍😃😎'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (..Before '😍') . should_equal '😍😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (..Before_Last '😍') . should_equal '😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (..After '😍') . should_equal '✨🚀🚧😍'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (..After_Last '😍') . should_equal '✨🚀🚧😍😃😍'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (..While c->c!="😃") . should_equal '😃😍😎😙😉☺'
|
||||
'✨🚀🚧😍😃😍😎😙😉☺'.drop (3.up_to 6) . should_equal '✨🚀🚧😎😙😉☺'
|
||||
|
||||
group_builder.specify "drop should correctly handle edge cases" <|
|
||||
"ABC".drop . should_equal "BC"
|
||||
|
||||
"".drop First . should_equal ""
|
||||
"".drop Last . should_equal ""
|
||||
"".drop ..First . should_equal ""
|
||||
"".drop ..Last . should_equal ""
|
||||
|
||||
"".drop (After "a") . should_equal ""
|
||||
"".drop (After_Last "a") . should_equal ""
|
||||
"".drop (Before "a") . should_equal ""
|
||||
"".drop (Before_Last "a") . should_equal ""
|
||||
"".drop (..After "a") . should_equal ""
|
||||
"".drop (..After_Last "a") . should_equal ""
|
||||
"".drop (..Before "a") . should_equal ""
|
||||
"".drop (..Before_Last "a") . should_equal ""
|
||||
|
||||
"".drop (After "") . should_equal ""
|
||||
"".drop (After_Last "") . should_equal ""
|
||||
"".drop (Before "") . should_equal ""
|
||||
"".drop (Before_Last "") . should_equal ""
|
||||
"".drop (..After "") . should_equal ""
|
||||
"".drop (..After_Last "") . should_equal ""
|
||||
"".drop (..Before "") . should_equal ""
|
||||
"".drop (..Before_Last "") . should_equal ""
|
||||
|
||||
"".drop (While _->True) . should_equal ""
|
||||
"".drop (..While _->True) . should_equal ""
|
||||
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
'ABC\u{301}'.drop (0.up_to 0) . should_equal 'ABC\u{301}'
|
||||
|
||||
'ABC\u{301}'.drop (After "") . should_equal ''
|
||||
'ABC\u{301}'.drop (After_Last "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.drop (Before "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.drop (Before_Last "") . should_equal ''
|
||||
'ABC\u{301}'.drop (..After "") . should_equal ''
|
||||
'ABC\u{301}'.drop (..After_Last "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.drop (..Before "") . should_equal 'ABC\u{301}'
|
||||
'ABC\u{301}'.drop (..Before_Last "") . should_equal ''
|
||||
|
||||
"ABC".drop (By_Index -1) . should_equal "AB"
|
||||
"ABC".drop (By_Index [-1, -1, -1, -3, 2]) . should_equal "B"
|
||||
"ABC".drop (By_Index []) . should_equal "ABC"
|
||||
"".drop (Every 2) . should_equal ""
|
||||
"".drop (Every 2 first=1) . should_equal ""
|
||||
"ABC".drop (Every 5) . should_equal "BC"
|
||||
"ABC".drop (Every 5 first=4) . should_equal "ABC"
|
||||
"".drop (Sample 0) . should_equal ""
|
||||
"".drop (Sample 100) . should_equal ""
|
||||
"ABC".drop (..By_Index -1) . should_equal "AB"
|
||||
"ABC".drop (..By_Index [-1, -1, -1, -3, 2]) . should_equal "B"
|
||||
"ABC".drop (..By_Index []) . should_equal "ABC"
|
||||
"".drop (..Every 2) . should_equal ""
|
||||
"".drop (..Every 2 first=1) . should_equal ""
|
||||
"ABC".drop (..Every 5) . should_equal "BC"
|
||||
"ABC".drop (..Every 5 first=4) . should_equal "ABC"
|
||||
"".drop (..Sample 0) . should_equal ""
|
||||
"".drop (..Sample 100) . should_equal ""
|
||||
|
||||
group_builder.specify "take and drop should gracefully handle missing constructor arguments" <|
|
||||
Test.expect_panic Type_Error <| "".take "FOO"
|
||||
Test.expect_panic Type_Error <| "".drop "FOO"
|
||||
|
||||
r1 = "".take (Index_Sub_Range.While)
|
||||
r1 = "".take (..While)
|
||||
r1.should_fail_with Missing_Argument
|
||||
r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`."
|
||||
|
||||
|
@ -181,7 +181,7 @@ add_specs suite_builder =
|
||||
time . millisecond . should_equal 0
|
||||
time . microsecond . should_equal 0
|
||||
time . nanosecond . should_equal 0
|
||||
time.zone.zone_id . take (Last 6) . should_equal "+01:00"
|
||||
time.zone.zone_id . take (..Last 6) . should_equal "+01:00"
|
||||
|
||||
group_builder.specify "should parse time with id-based zone" <|
|
||||
time = Date_Time.parse "1970-01-01T00:00:01+01:00[Europe/Paris]"
|
||||
@ -217,7 +217,7 @@ add_specs suite_builder =
|
||||
time . millisecond . should_equal 0
|
||||
time . microsecond . should_equal 0
|
||||
time . nanosecond . should_equal 0
|
||||
(time.zone.zone_id . take (Last 3) . to_case Case.Upper) . should_equal "UTC"
|
||||
(time.zone.zone_id . take (..Last 3) . to_case Case.Upper) . should_equal "UTC"
|
||||
|
||||
group_builder.specify "should parse custom format of local time" <|
|
||||
time = Date_Time.parse "06 of May 2020 at 04:30AM" "dd 'of' MMMM yyyy 'at' hh:mma"
|
||||
|
@ -6,18 +6,17 @@ from Standard.Test import all
|
||||
|
||||
add_specs suite_builder = suite_builder.group "Vector Slicing Helpers" group_builder->
|
||||
group_builder.specify "should be able to sort correctly merge neighboring sequences" <|
|
||||
merge = sort_and_merge_ranges
|
||||
merge [] . should_equal []
|
||||
merge [0.up_to 0] . should_equal []
|
||||
merge [0.up_to 10] . should_equal [0.up_to 10]
|
||||
merge [0.up_to 10, 2.up_to 4] . should_equal [0.up_to 10]
|
||||
merge [0.up_to 5, 5.up_to 10] . should_equal [0.up_to 10]
|
||||
merge [5.up_to 10, 0.up_to 0, 0.up_to 1, 1.up_to 5] . should_equal [0.up_to 10]
|
||||
merge [0.up_to 1, 1.up_to 2] . should_equal [0.up_to 2]
|
||||
merge [6.up_to 7, 7.up_to 8, 5.up_to 5, 0.up_to 1, 2.up_to 3] . should_equal [0.up_to 1, 2.up_to 3, 6.up_to 8]
|
||||
merge [5.up_to 10, 3.up_to 6, 3.up_to 6, 3.up_to 5, 3.up_to 7, 0.up_to 1] . should_equal [0.up_to 1, 3.up_to 10]
|
||||
merge [0.up_to 1, 0.up_to 1] . should_equal [0.up_to 1]
|
||||
merge [0.up_to 1, 1.up_to 2] . should_equal [0.up_to 2]
|
||||
sort_and_merge_ranges [] . should_equal []
|
||||
sort_and_merge_ranges [0.up_to 0] . should_equal []
|
||||
sort_and_merge_ranges [0.up_to 10] . should_equal [0.up_to 10]
|
||||
sort_and_merge_ranges [0.up_to 10, 2.up_to 4] . should_equal [0.up_to 10]
|
||||
sort_and_merge_ranges [0.up_to 5, 5.up_to 10] . should_equal [0.up_to 10]
|
||||
sort_and_merge_ranges [5.up_to 10, 0.up_to 0, 0.up_to 1, 1.up_to 5] . should_equal [0.up_to 10]
|
||||
sort_and_merge_ranges [0.up_to 1, 1.up_to 2] . should_equal [0.up_to 2]
|
||||
sort_and_merge_ranges [6.up_to 7, 7.up_to 8, 5.up_to 5, 0.up_to 1, 2.up_to 3] . should_equal [0.up_to 1, 2.up_to 3, 6.up_to 8]
|
||||
sort_and_merge_ranges [5.up_to 10, 3.up_to 6, 3.up_to 6, 3.up_to 5, 3.up_to 7, 0.up_to 1] . should_equal [0.up_to 1, 3.up_to 10]
|
||||
sort_and_merge_ranges [0.up_to 1, 0.up_to 1] . should_equal [0.up_to 1]
|
||||
sort_and_merge_ranges [0.up_to 1, 1.up_to 2] . should_equal [0.up_to 2]
|
||||
|
||||
main filter=Nothing =
|
||||
suite = Test.build suite_builder->
|
||||
|
@ -15,7 +15,6 @@ import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Unimplemented.Unimplemented
|
||||
import Standard.Base.Runtime.Ref.Ref
|
||||
import Standard.Base.Runtime.State
|
||||
from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import While, By_Index, Sample, Every
|
||||
from Standard.Base.Panic import Wrapped_Dataflow_Error
|
||||
|
||||
from Standard.Test import all
|
||||
@ -576,15 +575,15 @@ type_spec suite_builder name alter = suite_builder.group name group_builder->
|
||||
[].drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
vec.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
vec.take (First 4) . should_equal first_four
|
||||
vec.take (First 0) . should_equal []
|
||||
vec.take (First -1) . should_equal []
|
||||
vec.take (First 100) . should_equal vec
|
||||
vec.take (..First 4) . should_equal first_four
|
||||
vec.take (..First 0) . should_equal []
|
||||
vec.take (..First -1) . should_equal []
|
||||
vec.take (..First 100) . should_equal vec
|
||||
|
||||
vec.drop (First 2) . should_equal last_four
|
||||
vec.drop (First 0) . should_equal vec
|
||||
vec.drop (First -1) . should_equal vec
|
||||
vec.drop (First 100) . should_equal []
|
||||
vec.drop (..First 2) . should_equal last_four
|
||||
vec.drop (..First 0) . should_equal vec
|
||||
vec.drop (..First -1) . should_equal vec
|
||||
vec.drop (..First 100) . should_equal []
|
||||
|
||||
vec.take 4 . should_equal first_four
|
||||
vec.take 0 . should_equal []
|
||||
@ -596,106 +595,102 @@ type_spec suite_builder name alter = suite_builder.group name group_builder->
|
||||
vec.drop -1 . should_equal vec
|
||||
vec.drop 100 . should_equal []
|
||||
|
||||
vec.take (Last 4) . should_equal last_four
|
||||
vec.take (Last 0) . should_equal []
|
||||
vec.take (Last -1) . should_equal []
|
||||
vec.take (Last 100) . should_equal vec
|
||||
vec.take (..Last 4) . should_equal last_four
|
||||
vec.take (..Last 0) . should_equal []
|
||||
vec.take (..Last -1) . should_equal []
|
||||
vec.take (..Last 100) . should_equal vec
|
||||
|
||||
vec.drop (Last 2) . should_equal first_four
|
||||
vec.drop (Last 0) . should_equal vec
|
||||
vec.drop (Last -1) . should_equal vec
|
||||
vec.drop (Last 100) . should_equal []
|
||||
vec.drop (..Last 2) . should_equal first_four
|
||||
vec.drop (..Last 0) . should_equal vec
|
||||
vec.drop (..Last -1) . should_equal vec
|
||||
vec.drop (..Last 100) . should_equal []
|
||||
|
||||
vec.take (Every 1) . should_equal vec
|
||||
vec.take (Every 3) . should_equal [1, 4]
|
||||
vec.take (Every 3 first=1) . should_equal [2, 5]
|
||||
vec.take (Every 2 first=1) . should_equal [2, 4, 6]
|
||||
vec.take (Every 2 first=100) . should_equal []
|
||||
vec.take (Every 200) . should_equal [1]
|
||||
[].take (Every 2) . should_equal []
|
||||
vec.take (Every 0) . should_fail_with Illegal_Argument
|
||||
[].take (Every 0) . should_fail_with Illegal_Argument
|
||||
vec.take (..Every 1) . should_equal vec
|
||||
vec.take (..Every 3) . should_equal [1, 4]
|
||||
vec.take (..Every 3 first=1) . should_equal [2, 5]
|
||||
vec.take (..Every 2 first=1) . should_equal [2, 4, 6]
|
||||
vec.take (..Every 2 first=100) . should_equal []
|
||||
vec.take (..Every 200) . should_equal [1]
|
||||
[].take (..Every 2) . should_equal []
|
||||
vec.take (..Every 0) . should_fail_with Illegal_Argument
|
||||
[].take (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
vec.drop (Every 1) . should_equal []
|
||||
vec.drop (Every 3) . should_equal [2, 3, 5, 6]
|
||||
vec.drop (Every 3 first=1) . should_equal [1, 3, 4, 6]
|
||||
vec.drop (Every 2 first=1) . should_equal [1, 3, 5]
|
||||
vec.drop (Every 2 first=100) . should_equal vec
|
||||
vec.drop (Every 200) . should_equal [2, 3, 4, 5, 6]
|
||||
[].drop (Every 2) . should_equal []
|
||||
vec.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
[].drop (Every 0) . should_fail_with Illegal_Argument
|
||||
vec.drop (..Every 1) . should_equal []
|
||||
vec.drop (..Every 3) . should_equal [2, 3, 5, 6]
|
||||
vec.drop (..Every 3 first=1) . should_equal [1, 3, 4, 6]
|
||||
vec.drop (..Every 2 first=1) . should_equal [1, 3, 5]
|
||||
vec.drop (..Every 2 first=100) . should_equal vec
|
||||
vec.drop (..Every 200) . should_equal [2, 3, 4, 5, 6]
|
||||
[].drop (..Every 2) . should_equal []
|
||||
vec.drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
[].drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
vec.take (By_Index 0) . should_equal [1]
|
||||
[].take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (By_Index []) . should_equal []
|
||||
vec.take (By_Index [-1, -1]) . should_equal [6, 6]
|
||||
vec.take (By_Index [0, 0, 3.up_to 100]) . should_equal [1, 1, 4, 5, 6]
|
||||
vec.take (..By_Index 0) . should_equal [1]
|
||||
[].take (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (..By_Index []) . should_equal []
|
||||
vec.take (..By_Index [-1, -1]) . should_equal [6, 6]
|
||||
vec.take (..By_Index [0, 0, 3.up_to 100]) . should_equal [1, 1, 4, 5, 6]
|
||||
vec.take (0.up_to 100 . with_step 2) . should_equal [1, 3, 5]
|
||||
vec.take (By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal [1, 3, 5, 2, 4, 6]
|
||||
vec.take (By_Index [1.up_to 3, 2.up_to 5]) . should_equal [2, 3, 3, 4, 5]
|
||||
vec.take (By_Index [2.up_to 5, 1.up_to 3]) . should_equal [3, 4, 5, 2, 3]
|
||||
vec.take (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal [1, 3, 5, 2, 4, 6]
|
||||
vec.take (..By_Index [1.up_to 3, 2.up_to 5]) . should_equal [2, 3, 3, 4, 5]
|
||||
vec.take (..By_Index [2.up_to 5, 1.up_to 3]) . should_equal [3, 4, 5, 2, 3]
|
||||
vec.take (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
vec.drop (By_Index 0) . should_equal [2, 3, 4, 5, 6]
|
||||
vec.drop (By_Index []) . should_equal vec
|
||||
vec.drop (By_Index [-1, -1]) . should_equal [1, 2, 3, 4, 5]
|
||||
vec.drop (By_Index [0, 0, 3.up_to 100]) . should_equal [2, 3]
|
||||
vec.drop (..By_Index 0) . should_equal [2, 3, 4, 5, 6]
|
||||
vec.drop (..By_Index []) . should_equal vec
|
||||
vec.drop (..By_Index [-1, -1]) . should_equal [1, 2, 3, 4, 5]
|
||||
vec.drop (..By_Index [0, 0, 3.up_to 100]) . should_equal [2, 3]
|
||||
vec.drop (0.up_to 100 . with_step 2) . should_equal [2, 4, 6]
|
||||
vec.drop (By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal []
|
||||
vec.drop (By_Index [1.up_to 3, 2.up_to 5]) . should_equal [1, 6]
|
||||
vec.drop (By_Index [2.up_to 5, 1.up_to 3]) . should_equal [1, 6]
|
||||
vec.drop (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.drop (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal []
|
||||
vec.drop (..By_Index [1.up_to 3, 2.up_to 5]) . should_equal [1, 6]
|
||||
vec.drop (..By_Index [2.up_to 5, 1.up_to 3]) . should_equal [1, 6]
|
||||
vec.drop (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.drop (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
[1, 3, 5, 6, 8, 9, 10, 11, 13].take (While (x-> x%2 == 1)) . should_equal [1, 3, 5]
|
||||
alter [1, 2, 3] . take (While (_ > 10)) . should_equal []
|
||||
alter [1, 2, 3] . take (While (_ < 10)) . should_equal [1, 2, 3]
|
||||
[1, 3, 5, 6, 8, 9, 10, 11, 13].take (..While (x-> x%2 == 1)) . should_equal [1, 3, 5]
|
||||
alter [1, 2, 3] . take (..While (_ > 10)) . should_equal []
|
||||
alter [1, 2, 3] . take (..While (_ < 10)) . should_equal [1, 2, 3]
|
||||
|
||||
[1, 3, 5, 6, 8, 9, 10, 11, 13].drop (While (x-> x%2 == 1)) . should_equal [6, 8, 9, 10, 11, 13]
|
||||
alter [1, 2, 3] . drop (While (_ > 10)) . should_equal [1, 2, 3]
|
||||
alter [1, 2, 3] . drop (While (_ < 10)) . should_equal []
|
||||
[1, 3, 5, 6, 8, 9, 10, 11, 13].drop (..While (x-> x%2 == 1)) . should_equal [6, 8, 9, 10, 11, 13]
|
||||
alter [1, 2, 3] . drop (..While (_ > 10)) . should_equal [1, 2, 3]
|
||||
alter [1, 2, 3] . drop (..While (_ < 10)) . should_equal []
|
||||
|
||||
vec.take (Sample 0) . should_equal []
|
||||
alter [] . take (Sample 0) . should_equal []
|
||||
alter [] . take (Sample 1) . should_fail_with Illegal_Argument
|
||||
alter ["a"] . take (Sample 1) . should_equal ["a"]
|
||||
alter ["a", "a", "a"] . take (Sample 1) . should_equal ["a"]
|
||||
alter ["a", "a", "a"] . take (Sample 3) . should_equal ["a", "a", "a"]
|
||||
alter ["a", "a", "a"] . take (Sample 100) . should_fail_with Illegal_Argument
|
||||
vec.take (..Sample 0) . should_equal []
|
||||
alter [] . take (..Sample 0) . should_equal []
|
||||
alter [] . take (..Sample 1) . should_fail_with Illegal_Argument
|
||||
alter ["a"] . take (..Sample 1) . should_equal ["a"]
|
||||
alter ["a", "a", "a"] . take (..Sample 1) . should_equal ["a"]
|
||||
alter ["a", "a", "a"] . take (..Sample 3) . should_equal ["a", "a", "a"]
|
||||
alter ["a", "a", "a"] . take (..Sample 100) . should_fail_with Illegal_Argument
|
||||
|
||||
vec.drop (Sample 0) . should_equal vec
|
||||
alter [] . drop (Sample 0) . should_equal []
|
||||
alter [] . drop (Sample 1) . should_equal []
|
||||
alter ["a"] . drop (Sample 1) . should_equal []
|
||||
alter ["a", "a", "a"] . drop (Sample 1) . should_equal ["a", "a"]
|
||||
alter ["a", "a", "a"] . drop (Sample 100) . should_equal []
|
||||
vec.drop (..Sample 0) . should_equal vec
|
||||
alter [] . drop (..Sample 0) . should_equal []
|
||||
alter [] . drop (..Sample 1) . should_equal []
|
||||
alter ["a"] . drop (..Sample 1) . should_equal []
|
||||
alter ["a", "a", "a"] . drop (..Sample 1) . should_equal ["a", "a"]
|
||||
alter ["a", "a", "a"] . drop (..Sample 100) . should_equal []
|
||||
|
||||
suite_builder.group "take/drop Sample non-determinism" group_builder->
|
||||
v = 0.up_to 60 . to_vector
|
||||
|
||||
group_builder.specify "sampling should be deterministic when a seed is supplied" <|
|
||||
v.take (Sample 5 seed=4200000) . should_equal (v.take (Sample 5 seed=4200000))
|
||||
v.take (..Sample 5 seed=4200000) . should_equal (v.take (..Sample 5 seed=4200000))
|
||||
|
||||
group_builder.specify "sampling should be non-deterministic when a seed is not supplied" <|
|
||||
v.take (Sample 5) . should_not_equal (v.take (Sample 5))
|
||||
v.take (..Sample 5) . should_not_equal (v.take (..Sample 5))
|
||||
|
||||
group_builder.specify "take/drop should gracefully handle missing constructor arguments" <|
|
||||
Test.expect_panic Type_Error <| [].take "FOO"
|
||||
Test.expect_panic Type_Error <| [].drop "FOO"
|
||||
|
||||
r1 = [].take (Index_Sub_Range.While)
|
||||
r1 = [].take (..While)
|
||||
r1.should_fail_with Missing_Argument
|
||||
r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`."
|
||||
|
||||
r2 = [].drop (Index_Sub_Range.Every ...)
|
||||
r2.should_fail_with Illegal_Argument
|
||||
r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments"
|
||||
|
||||
r3 = [].take (Index_Sub_Range.First _)
|
||||
r3.should_fail_with Illegal_Argument
|
||||
r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?"
|
||||
r2 = [].take (..By_Index)
|
||||
r2.should_fail_with Missing_Argument
|
||||
r2.catch.to_display_text . should_contain "Provide a value for the argument `indexes`."
|
||||
|
||||
group_builder.specify "should allow getting the last element of the vector" <|
|
||||
non_empty_vec = alter [1, 2, 3, 4, 5]
|
||||
|
@ -16,6 +16,6 @@ add_specs suite_builder = suite_builder.group "Stack traces" group_builder->
|
||||
modname = Meta.get_simple_type_name Stack_Traces_Spec
|
||||
stack = My_Type.foo
|
||||
names = [modname + ".bar", modname + ".baz", "Number.foo", modname + ".foo", "My_Type.foo"]
|
||||
stack.take (First 5) . map .name . should_equal names
|
||||
stack.take (..First 5) . map .name . should_equal names
|
||||
file = enso_project.root / 'src' / 'Runtime' / 'Stack_Traces_Spec.enso'
|
||||
stack.take (First 5) . map (.source_location >> .file) . each (_.should_equal file)
|
||||
stack.take (..First 5) . map (.source_location >> .file) . each (_.should_equal file)
|
||||
|
@ -265,7 +265,7 @@ add_specs suite_builder =
|
||||
group_builder.specify "Requesting Text & Foo" <|
|
||||
check a (n : Text & Foo) = case a of
|
||||
0 -> n.foo
|
||||
1 -> n.take (First 3)
|
||||
1 -> n.take (..First 3)
|
||||
|
||||
check 0 "Ahoj" . should_equal 4
|
||||
check 1 "Ahoj" . should_equal "Aho"
|
||||
|
@ -17,7 +17,7 @@ add_specs suite_builder = suite_builder.group "Meta-Value Inspection" group_buil
|
||||
group_builder.specify "should allow to get the source location of a frame" pending=location_pending <|
|
||||
src = Meta.get_source_location 0
|
||||
loc = "Meta_Location_Spec.enso:18:15-40"
|
||||
src.take (Last loc.length) . should_equal loc
|
||||
src.take (..Last loc.length) . should_equal loc
|
||||
|
||||
group_builder.specify "should allow to get qualified type names of values" <|
|
||||
x = 42
|
||||
|
@ -162,7 +162,7 @@ add_specs suite_builder = suite_builder.group "Dataflow Warnings" group_builder-
|
||||
current = Runtime.get_stack_trace
|
||||
warned = foo "value"
|
||||
warning_stack = Warning.get_all warned . first . origin
|
||||
relevant = warning_stack . drop (Last current.length)
|
||||
relevant = warning_stack . drop (..Last current.length)
|
||||
relevant.map .name . should_equal (['baz', 'bar', 'foo'].map ('Warnings_Spec.'+))
|
||||
|
||||
group_builder.specify "should attach reassignment info in the last-reassigned-first order" <|
|
||||
|
@ -283,12 +283,12 @@ add_specs suite_builder =
|
||||
suite_builder.group "read_bytes" group_builder->
|
||||
group_builder.specify "should allow reading a file to byte vector" <|
|
||||
contents = sample_file.read_bytes
|
||||
contents.take (First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
contents.take (..First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
|
||||
group_builder.specify "should allow reading a file to byte vector via path" <|
|
||||
full_path = sample_file . path
|
||||
contents = File.new full_path . read_bytes
|
||||
contents.take (First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
contents.take (..First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
|
||||
group_builder.specify "should allow to read last n bytes from a file" <|
|
||||
file = enso_project.data / "transient" / "bytes.txt"
|
||||
@ -312,10 +312,10 @@ add_specs suite_builder =
|
||||
group_builder.specify "should open and read the file in one shot" <|
|
||||
path_name = sample_file.path
|
||||
contents = File.new path_name . read_bytes
|
||||
contents.take (First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
contents.take (..First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
file = sample_file
|
||||
contents_2 = File.new file . read_bytes
|
||||
contents_2.take (First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
contents_2.take (..First 6) . should_equal [67, 117, 112, 99, 97, 107]
|
||||
|
||||
suite_builder.group "Path Operations" group_builder->
|
||||
group_builder.specify "should allow going above the first part of a relative directory by resolving it to absolute" <|
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Table import Table, Aggregate_Column
|
||||
|
||||
|
@ -13,7 +13,7 @@ type Scenario
|
||||
Value table1 table2
|
||||
|
||||
shuffle vec =
|
||||
vec.take (Index_Sub_Range.Sample vec.length seed=42)
|
||||
vec.take (..Sample vec.length seed=42)
|
||||
|
||||
create_scenario_equals num_rows =
|
||||
xs = (0.up_to num_rows).to_vector
|
||||
|
@ -21,7 +21,7 @@ Comparable.from (_:My) = My_Comparator
|
||||
|
||||
vector_size = 100000
|
||||
|
||||
create_ints = (0.up_to vector_size).to_vector.take (Index_Sub_Range.Sample vector_size 42)
|
||||
create_ints = (0.up_to vector_size).to_vector.take (..Sample vector_size 42)
|
||||
|
||||
create_dates = create_ints.map x->
|
||||
(Date_Time.new 1990 1 1) + (Duration.new seconds=x)
|
||||
|
@ -19,7 +19,7 @@ create_dates =
|
||||
|
||||
create_holidays =
|
||||
dates = create_dates
|
||||
dates.take (Index_Sub_Range.Sample 100 100)
|
||||
dates.take (..Sample 100 100)
|
||||
|
||||
|
||||
create_shifted_dates shift =
|
||||
|
@ -50,10 +50,10 @@ collect_benches = Bench.build builder->
|
||||
random_vec.reduce (+)
|
||||
|
||||
group_builder.specify "Drop_First_20_and_Sum" <|
|
||||
(random_vec.drop (First 20)).reduce (+)
|
||||
(random_vec.drop (..First 20)).reduce (+)
|
||||
|
||||
group_builder.specify "Drop_Last_20_and_Sum" <|
|
||||
(random_vec.drop (Last 20)).reduce (+)
|
||||
(random_vec.drop (..Last 20)).reduce (+)
|
||||
|
||||
group_builder.specify "Filter" <|
|
||||
random_vec.filter (x -> x % 3 == 1)
|
||||
|
@ -29,7 +29,7 @@ pending = if should_run_test then Nothing else """
|
||||
bin_dir =
|
||||
p = Java_System.getProperty "jdk.module.path"
|
||||
s = p.split Java_File.separator
|
||||
paths = s.take (Index_Sub_Range.While _!="..")
|
||||
paths = s.take (..While _!="..")
|
||||
j = paths . join Java_File.separator
|
||||
File.new j
|
||||
|
||||
|
@ -575,7 +575,7 @@ add_snowflake_specs suite_builder create_connection_fn db_name =
|
||||
agg_in_memory_table.select_into_database_table default_connection.get (Name_Generator.random_name "Agg1") primary_key=Nothing temporary=True
|
||||
|
||||
empty_agg_table_fn = _->
|
||||
(agg_in_memory_table.take (First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
(agg_in_memory_table.take (..First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
|
||||
setup = Common_Table_Operations.Main.Test_Setup.Config prefix agg_table_fn empty_agg_table_fn table_builder materialize is_database=True test_selection=common_selection aggregate_test_selection=aggregate_selection create_connection_func=create_connection_fn light_table_builder=light_table_builder
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
|
||||
from Standard.Table import Table, Sort_Column, expr
|
||||
from Standard.Table.Aggregate_Column.Aggregate_Column import all
|
||||
|
@ -257,7 +257,7 @@ add_specs suite_builder setup =
|
||||
# 6. multiple Between conditions
|
||||
xs = [0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4]
|
||||
ys = [1, 2, 3, 1, 9, 2, 3, 2, 4, 2, 1, 1, 1, 2]
|
||||
pts = xs.zip ys . take (Index_Sub_Range.Sample xs.length seed=42)
|
||||
pts = xs.zip ys . take (..Sample xs.length seed=42)
|
||||
t1 = table_builder [["X", pts.map .first], ["Y", pts.map .second]]
|
||||
|
||||
t2 = table_builder [["lx", [1]], ["ux", [3]], ["ly", [1]], ["uy", [2]]]
|
||||
|
@ -1,5 +1,4 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import While, Sample, Every
|
||||
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
|
||||
import Standard.Base.Errors.Common.Missing_Argument
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
@ -82,15 +81,15 @@ add_specs suite_builder setup =
|
||||
data.table.take.at "beta" . to_vector . should_equal ["A"]
|
||||
data.table.drop.at "alpha" . to_vector . should_equal [2,3,4,5,6,7,8]
|
||||
|
||||
data.table.take (First 4) . at "alpha" . to_vector . should_equal [1,2,3,4]
|
||||
data.table.take (First 0) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (First -1) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (First 100) . should_equal data.table
|
||||
data.table.take (..First 4) . at "alpha" . to_vector . should_equal [1,2,3,4]
|
||||
data.table.take (..First 0) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (..First -1) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (..First 100) . should_equal data.table
|
||||
|
||||
data.table.drop (First 2) . at "beta" . to_vector . should_equal ["C","D","E","F","G","H"]
|
||||
data.table.drop (First 0) . should_equal data.table
|
||||
data.table.drop (First -1) . should_equal data.table
|
||||
data.table.drop (First 100) . should_equal data.empty
|
||||
data.table.drop (..First 2) . at "beta" . to_vector . should_equal ["C","D","E","F","G","H"]
|
||||
data.table.drop (..First 0) . should_equal data.table
|
||||
data.table.drop (..First -1) . should_equal data.table
|
||||
data.table.drop (..First 100) . should_equal data.empty
|
||||
|
||||
data.table.take 4 . at "alpha" . to_vector . should_equal [1,2,3,4]
|
||||
data.table.take 0 . at "alpha" . to_vector . should_equal []
|
||||
@ -102,15 +101,15 @@ add_specs suite_builder setup =
|
||||
data.table.drop -1 . should_equal data.table
|
||||
data.table.drop 100 . should_equal data.empty
|
||||
|
||||
data.table.take (Last 4) . at "beta" . to_vector . should_equal ["E","F","G","H"]
|
||||
data.table.take (Last 0) . should_equal data.empty
|
||||
data.table.take (Last -1) . should_equal data.empty
|
||||
data.table.take (Last 100) . should_equal data.table
|
||||
data.table.take (..Last 4) . at "beta" . to_vector . should_equal ["E","F","G","H"]
|
||||
data.table.take (..Last 0) . should_equal data.empty
|
||||
data.table.take (..Last -1) . should_equal data.empty
|
||||
data.table.take (..Last 100) . should_equal data.table
|
||||
|
||||
data.table.drop (Last 2) . at "alpha" . to_vector . should_equal [1,2,3,4,5,6]
|
||||
data.table.drop (Last 0) . should_equal data.table
|
||||
data.table.drop (Last -1) . should_equal data.table
|
||||
data.table.drop (Last 100) . should_equal data.empty
|
||||
data.table.drop (..Last 2) . at "alpha" . to_vector . should_equal [1,2,3,4,5,6]
|
||||
data.table.drop (..Last 0) . should_equal data.table
|
||||
data.table.drop (..Last -1) . should_equal data.table
|
||||
data.table.drop (..Last 100) . should_equal data.empty
|
||||
|
||||
group_builder.specify "should handle consecutive take/drops" <|
|
||||
data.table.take 5 . sort "alpha" . take 3 . at "alpha" . to_vector . should_equal [1, 2, 3]
|
||||
@ -141,49 +140,49 @@ add_specs suite_builder setup =
|
||||
data.empty.drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
data.table.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
data.table.take (Index_Sub_Range.By_Index 0) . at "beta" . to_vector . should_equal ["A"]
|
||||
data.empty.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.take (Index_Sub_Range.By_Index []) . should_equal data.empty
|
||||
data.table.take (Index_Sub_Range.By_Index [-1, -1]) . at "beta" . to_vector . should_equal ["H", "H"]
|
||||
data.table.take (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . at "alpha" . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
data.table.take (..By_Index 0) . at "beta" . to_vector . should_equal ["A"]
|
||||
data.empty.take (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.take (..By_Index []) . should_equal data.empty
|
||||
data.table.take (..By_Index [-1, -1]) . at "beta" . to_vector . should_equal ["H", "H"]
|
||||
data.table.take (..By_Index [0, 0, 3.up_to 100]) . at "alpha" . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
data.table.take (0.up_to 100 . with_step 2) . at "alpha" . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.table.take (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
data.table.take (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
data.table.take (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
data.table.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.take (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
data.table.take (..By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
data.table.take (..By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
data.table.take (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.take (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
data.table.drop (Index_Sub_Range.By_Index 0) . at "alpha" . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
data.table.drop (Index_Sub_Range.By_Index []) . should_equal data.table
|
||||
data.table.drop (Index_Sub_Range.By_Index [-1, -1]) . at "alpha" . to_vector . should_equal [1, 2, 3, 4, 5, 6, 7]
|
||||
data.table.drop (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . at "alpha" . to_vector . should_equal [2, 3]
|
||||
data.table.drop (..By_Index 0) . at "alpha" . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
data.table.drop (..By_Index []) . should_equal data.table
|
||||
data.table.drop (..By_Index [-1, -1]) . at "alpha" . to_vector . should_equal [1, 2, 3, 4, 5, 6, 7]
|
||||
data.table.drop (..By_Index [0, 0, 3.up_to 100]) . at "alpha" . to_vector . should_equal [2, 3]
|
||||
data.table.drop (0.up_to 100 . with_step 2) . at "alpha" . to_vector . should_equal [2, 4, 6, 8]
|
||||
data.table.drop (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [8]
|
||||
data.table.drop (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.table.drop (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.table.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.drop (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [8]
|
||||
data.table.drop (..By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.table.drop (..By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.table.drop (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.table.drop (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
group_builder.specify "should allow selecting every Nth row" <|
|
||||
data.table.take (Every 1) . should_equal data.table
|
||||
data.table.take (Every 3) . at "alpha" . to_vector . should_equal [1, 4, 7]
|
||||
data.table.take (Every 3 first=1) . at "alpha" . to_vector . should_equal [2, 5, 8]
|
||||
data.table.take (Every 2 first=1) . at "beta" . to_vector . should_equal ["B", "D", "F", "H"]
|
||||
data.table.take (Every 2 first=100) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (Every 200) . at "alpha" . to_vector . should_equal [1]
|
||||
data.empty.take (Every 2) . should_equal data.empty
|
||||
data.table.take (Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty.take (Every 0) . should_fail_with Illegal_Argument
|
||||
data.table.take (..Every 1) . should_equal data.table
|
||||
data.table.take (..Every 3) . at "alpha" . to_vector . should_equal [1, 4, 7]
|
||||
data.table.take (..Every 3 first=1) . at "alpha" . to_vector . should_equal [2, 5, 8]
|
||||
data.table.take (..Every 2 first=1) . at "beta" . to_vector . should_equal ["B", "D", "F", "H"]
|
||||
data.table.take (..Every 2 first=100) . at "alpha" . to_vector . should_equal []
|
||||
data.table.take (..Every 200) . at "alpha" . to_vector . should_equal [1]
|
||||
data.empty.take (..Every 2) . should_equal data.empty
|
||||
data.table.take (..Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty.take (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
data.table.drop (Every 1) . should_equal data.empty
|
||||
data.table.drop (Every 3) . at "alpha" . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
data.table.drop (Every 3 first=1) . at "alpha" . to_vector . should_equal [1, 3, 4, 6, 7]
|
||||
data.table.drop (Every 2 first=1) . at "alpha" . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.table.drop (Every 2 first=100) . should_equal data.table
|
||||
data.table.drop (Every 200) . at "beta" . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
data.empty.drop (Every 2) . should_equal data.empty
|
||||
data.table.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
data.table.drop (..Every 1) . should_equal data.empty
|
||||
data.table.drop (..Every 3) . at "alpha" . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
data.table.drop (..Every 3 first=1) . at "alpha" . to_vector . should_equal [1, 3, 4, 6, 7]
|
||||
data.table.drop (..Every 2 first=1) . at "alpha" . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.table.drop (..Every 2 first=100) . should_equal data.table
|
||||
data.table.drop (..Every 200) . at "beta" . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
data.empty.drop (..Every 2) . should_equal data.empty
|
||||
data.table.drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty.drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
if setup.is_database.not then
|
||||
group_builder.specify "should allow sampling rows" <|
|
||||
@ -191,20 +190,20 @@ add_specs suite_builder setup =
|
||||
two = table_builder [["X", ["a", "a"]]] . sort "X"
|
||||
three = table_builder [["X", ["a", "a", "a"]]] . sort "X"
|
||||
empty = one.remove_all_rows
|
||||
three.take (Sample 0) . should_equal empty
|
||||
empty.take (Sample 0) . should_equal empty
|
||||
empty.take (Sample 1) . should_equal empty
|
||||
three.take (Sample 1) . should_equal one
|
||||
three.take (Sample 100) . should_equal three
|
||||
three.take (..Sample 0) . should_equal empty
|
||||
empty.take (..Sample 0) . should_equal empty
|
||||
empty.take (..Sample 1) . should_equal empty
|
||||
three.take (..Sample 1) . should_equal one
|
||||
three.take (..Sample 100) . should_equal three
|
||||
|
||||
three.drop (Sample 0) . should_equal three
|
||||
empty.drop (Sample 0) . should_equal empty
|
||||
empty.drop (Sample 1) . should_equal empty
|
||||
one.drop (Sample 1) . should_equal empty
|
||||
three.drop (Sample 1) . should_equal two
|
||||
three.drop (Sample 100) . should_equal empty
|
||||
three.drop (..Sample 0) . should_equal three
|
||||
empty.drop (..Sample 0) . should_equal empty
|
||||
empty.drop (..Sample 1) . should_equal empty
|
||||
one.drop (..Sample 1) . should_equal empty
|
||||
three.drop (..Sample 1) . should_equal two
|
||||
three.drop (..Sample 100) . should_equal empty
|
||||
|
||||
rnd = data.table.take (Sample 3 seed=42)
|
||||
rnd = data.table.take (..Sample 3 seed=42)
|
||||
random_indices = [5, 6, 2]
|
||||
alpha_sample = random_indices.map (data.table.at "alpha" . to_vector . at _)
|
||||
beta_sample = random_indices.map (data.table.at "beta" . to_vector . at _)
|
||||
@ -212,17 +211,17 @@ add_specs suite_builder setup =
|
||||
rnd.at "beta" . to_vector . should_equal beta_sample
|
||||
|
||||
group_builder.specify "sampling should be deterministic when a seed is supplied" <|
|
||||
data.table.take (Sample 3 seed=4200000) . should_equal (data.table.take (Sample 3 seed=4200000))
|
||||
data.table.take (..Sample 3 seed=4200000) . should_equal (data.table.take (..Sample 3 seed=4200000))
|
||||
|
||||
group_builder.specify "sampling should be non-deterministic when a seed is not supplied" <|
|
||||
0.up_to 3 . map _->
|
||||
data.table.take (Sample 3) . should_not_equal (data.table.take (Sample 3))
|
||||
data.table.take (..Sample 3) . should_not_equal (data.table.take (..Sample 3))
|
||||
|
||||
if setup.is_database.not then
|
||||
group_builder.specify "should allow selecting rows as long as they satisfy a predicate" <|
|
||||
t = table_builder [["a", [1, 2, 3, 4]], ["b", [5, 6, 7, 8]]]
|
||||
|
||||
t2 = t.take (While (row -> row.at "a" < 3))
|
||||
t2 = t.take (..While (row -> row.at "a" < 3))
|
||||
t2.row_count . should_equal 2
|
||||
t2.at "a" . to_vector . should_equal [1, 2]
|
||||
t2.at "b" . to_vector . should_equal [5, 6]
|
||||
@ -232,7 +231,7 @@ add_specs suite_builder setup =
|
||||
Test.expect_panic Type_Error <| t.take "FOO"
|
||||
Test.expect_panic Type_Error <| t.drop "FOO"
|
||||
|
||||
r1 = t.take (Index_Sub_Range.While)
|
||||
r1 = t.take (..While)
|
||||
r1.should_fail_with Missing_Argument
|
||||
r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`."
|
||||
|
||||
@ -271,35 +270,35 @@ add_specs suite_builder setup =
|
||||
data.beta.take.to_vector . should_equal ["A"]
|
||||
data.alpha.drop.to_vector . should_equal [2,3,4,5,6,7,8]
|
||||
|
||||
data.alpha.take (First 4) . to_vector . should_equal [1,2,3,4]
|
||||
data.alpha.take (First 0) . should_equal data.empty_alpha
|
||||
data.alpha.take (First -1) . should_equal data.empty_alpha
|
||||
data.alpha.take (First 100) . should_equal data.alpha
|
||||
data.alpha.take (..First 4) . to_vector . should_equal [1,2,3,4]
|
||||
data.alpha.take (..First 0) . should_equal data.empty_alpha
|
||||
data.alpha.take (..First -1) . should_equal data.empty_alpha
|
||||
data.alpha.take (..First 100) . should_equal data.alpha
|
||||
|
||||
data.alpha.take 4 . to_vector . should_equal [1,2,3,4]
|
||||
data.alpha.take 0 . should_equal data.empty_alpha
|
||||
data.alpha.take -1 . should_equal data.empty_alpha
|
||||
data.alpha.take 100 . should_equal data.alpha
|
||||
|
||||
data.beta.drop (First 2) . to_vector . should_equal ["C","D","E","F","G","H"]
|
||||
data.alpha.drop (First 0) . should_equal data.alpha
|
||||
data.alpha.drop (First -1) . should_equal data.alpha
|
||||
data.alpha.drop (First 100) . should_equal data.empty_alpha
|
||||
data.beta.drop (..First 2) . to_vector . should_equal ["C","D","E","F","G","H"]
|
||||
data.alpha.drop (..First 0) . should_equal data.alpha
|
||||
data.alpha.drop (..First -1) . should_equal data.alpha
|
||||
data.alpha.drop (..First 100) . should_equal data.empty_alpha
|
||||
|
||||
data.beta.drop 2 . to_vector . should_equal ["C","D","E","F","G","H"]
|
||||
data.alpha.drop 0 . should_equal data.alpha
|
||||
data.alpha.drop -1 . should_equal data.alpha
|
||||
data.alpha.drop 100 . should_equal data.empty_alpha
|
||||
|
||||
data.beta.take (Last 4) . to_vector . should_equal ["E","F","G","H"]
|
||||
data.beta.take (Last 0) . should_equal data.empty_beta
|
||||
data.beta.take (Last -1) . should_equal data.empty_beta
|
||||
data.beta.take (Last 100) . should_equal data.beta
|
||||
data.beta.take (..Last 4) . to_vector . should_equal ["E","F","G","H"]
|
||||
data.beta.take (..Last 0) . should_equal data.empty_beta
|
||||
data.beta.take (..Last -1) . should_equal data.empty_beta
|
||||
data.beta.take (..Last 100) . should_equal data.beta
|
||||
|
||||
data.alpha.drop (Last 2) . to_vector . should_equal [1,2,3,4,5,6]
|
||||
data.alpha.drop (Last 0) . should_equal data.alpha
|
||||
data.alpha.drop (Last -1) . should_equal data.alpha
|
||||
data.alpha.drop (Last 100) . should_equal data.empty_alpha
|
||||
data.alpha.drop (..Last 2) . to_vector . should_equal [1,2,3,4,5,6]
|
||||
data.alpha.drop (..Last 0) . should_equal data.alpha
|
||||
data.alpha.drop (..Last -1) . should_equal data.alpha
|
||||
data.alpha.drop (..Last 100) . should_equal data.empty_alpha
|
||||
|
||||
group_builder.specify "should handle consecutive take/drops" <|
|
||||
data.alpha.take 5 . sort . take 3 . to_vector . should_equal [1, 2, 3]
|
||||
@ -330,49 +329,49 @@ add_specs suite_builder setup =
|
||||
data.empty_alpha.drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
data.alpha.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
data.beta.take (Index_Sub_Range.By_Index 0) . to_vector . should_equal ["A"]
|
||||
data.empty_beta.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
data.beta.take (Index_Sub_Range.By_Index []) . should_equal data.empty_beta
|
||||
data.beta.take (Index_Sub_Range.By_Index [-1, -1]) . to_vector . should_equal ["H", "H"]
|
||||
data.alpha.take (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
data.beta.take (..By_Index 0) . to_vector . should_equal ["A"]
|
||||
data.empty_beta.take (..By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
data.beta.take (..By_Index []) . should_equal data.empty_beta
|
||||
data.beta.take (..By_Index [-1, -1]) . to_vector . should_equal ["H", "H"]
|
||||
data.alpha.take (..By_Index [0, 0, 3.up_to 100]) . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
data.alpha.take (0.up_to 100 . with_step 2) . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.alpha.take (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
data.alpha.take (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
data.alpha.take (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
data.alpha.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.take (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
data.alpha.take (..By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
data.alpha.take (..By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
data.alpha.take (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.take (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
data.alpha.drop (Index_Sub_Range.By_Index 0) . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index []) . should_equal data.alpha
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [-1, -1]) . to_vector . should_equal [1, 2, 3, 4, 5, 6, 7]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . to_vector . should_equal [2, 3]
|
||||
data.alpha.drop (..By_Index 0) . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
data.alpha.drop (..By_Index []) . should_equal data.alpha
|
||||
data.alpha.drop (..By_Index [-1, -1]) . to_vector . should_equal [1, 2, 3, 4, 5, 6, 7]
|
||||
data.alpha.drop (..By_Index [0, 0, 3.up_to 100]) . to_vector . should_equal [2, 3]
|
||||
data.alpha.drop (0.up_to 100 . with_step 2) . to_vector . should_equal [2, 4, 6, 8]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [8]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.alpha.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.drop (..By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [8]
|
||||
data.alpha.drop (..By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.alpha.drop (..By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
data.alpha.drop (..By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
data.alpha.drop (..By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
group_builder.specify "should allow selecting every Nth row" <|
|
||||
data.alpha.take (Every 1) . should_equal data.alpha
|
||||
data.alpha.take (Every 3) . to_vector . should_equal [1, 4, 7]
|
||||
data.alpha.take (Every 3 first=1) . to_vector . should_equal [2, 5, 8]
|
||||
data.beta.take (Every 2 first=1) . to_vector . should_equal ["B", "D", "F", "H"]
|
||||
data.alpha.take (Every 2 first=100) . to_vector . should_equal []
|
||||
data.alpha.take (Every 200) . to_vector . should_equal [1]
|
||||
data.empty_beta.take (Every 2) . should_equal data.empty_beta
|
||||
data.beta.take (Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty_beta.take (Every 0) . should_fail_with Illegal_Argument
|
||||
data.alpha.take (..Every 1) . should_equal data.alpha
|
||||
data.alpha.take (..Every 3) . to_vector . should_equal [1, 4, 7]
|
||||
data.alpha.take (..Every 3 first=1) . to_vector . should_equal [2, 5, 8]
|
||||
data.beta.take (..Every 2 first=1) . to_vector . should_equal ["B", "D", "F", "H"]
|
||||
data.alpha.take (..Every 2 first=100) . to_vector . should_equal []
|
||||
data.alpha.take (..Every 200) . to_vector . should_equal [1]
|
||||
data.empty_beta.take (..Every 2) . should_equal data.empty_beta
|
||||
data.beta.take (..Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty_beta.take (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
data.alpha.drop (Every 1) . should_equal data.empty_alpha
|
||||
data.alpha.drop (Every 3) . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
data.alpha.drop (Every 3 first=1) . to_vector . should_equal [1, 3, 4, 6, 7]
|
||||
data.alpha.drop (Every 2 first=1) . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.alpha.drop (Every 2 first=100) . should_equal data.alpha
|
||||
data.beta.drop (Every 200) . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
data.empty_beta.drop (Every 2) . should_equal data.empty_beta
|
||||
data.beta.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty_beta.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
data.alpha.drop (..Every 1) . should_equal data.empty_alpha
|
||||
data.alpha.drop (..Every 3) . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
data.alpha.drop (..Every 3 first=1) . to_vector . should_equal [1, 3, 4, 6, 7]
|
||||
data.alpha.drop (..Every 2 first=1) . to_vector . should_equal [1, 3, 5, 7]
|
||||
data.alpha.drop (..Every 2 first=100) . should_equal data.alpha
|
||||
data.beta.drop (..Every 200) . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
data.empty_beta.drop (..Every 2) . should_equal data.empty_beta
|
||||
data.beta.drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
data.empty_beta.drop (..Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
if setup.is_database.not then
|
||||
group_builder.specify "should allow sampling rows" <|
|
||||
@ -382,56 +381,60 @@ add_specs suite_builder setup =
|
||||
one = one_table . at "X"
|
||||
empty = one_table.remove_all_rows . at "X"
|
||||
|
||||
three.take (First 2) . should_equal two
|
||||
three.take First . should_equal one
|
||||
three.take (First 0) . should_equal empty
|
||||
three.take (..First 2) . should_equal two
|
||||
three.take ..First . should_equal one
|
||||
three.take (..First 0) . should_equal empty
|
||||
|
||||
three.take 2 . should_equal two
|
||||
three.take . should_equal one
|
||||
three.take 0 . should_equal empty
|
||||
|
||||
three.take (Sample 0) . should_equal empty
|
||||
empty.take (Sample 0) . should_equal empty
|
||||
empty.take (Sample 1) . should_equal empty
|
||||
three.take (Sample 1) . should_equal one
|
||||
three.take (Sample 100) . should_equal three
|
||||
three.take (..Sample 0) . should_equal empty
|
||||
empty.take (..Sample 0) . should_equal empty
|
||||
empty.take (..Sample 1) . should_equal empty
|
||||
three.take (..Sample 1) . should_equal one
|
||||
three.take (..Sample 100) . should_equal three
|
||||
|
||||
three.drop (Sample 0) . should_equal three
|
||||
empty.drop (Sample 0) . should_equal empty
|
||||
empty.drop (Sample 1) . should_equal empty
|
||||
one.drop (Sample 1) . should_equal empty
|
||||
three.drop (Sample 1) . should_equal two
|
||||
three.drop (Sample 100) . should_equal empty
|
||||
three.drop (..Sample 0) . should_equal three
|
||||
empty.drop (..Sample 0) . should_equal empty
|
||||
empty.drop (..Sample 1) . should_equal empty
|
||||
one.drop (..Sample 1) . should_equal empty
|
||||
three.drop (..Sample 1) . should_equal two
|
||||
three.drop (..Sample 100) . should_equal empty
|
||||
|
||||
rnd = data.alpha.take (Sample 3 seed=42)
|
||||
rnd = data.alpha.take (..Sample 3 seed=42)
|
||||
random_indices = [5, 6, 2]
|
||||
sample = data.alpha.take (Index_Sub_Range.By_Index random_indices)
|
||||
sample = data.alpha.take (..By_Index random_indices)
|
||||
rnd.should_equal sample
|
||||
|
||||
if setup.is_database.not then
|
||||
group_builder.specify "should allow selecting rows as long as they satisfy a predicate" <|
|
||||
col = table_builder [["X", [1, 3, 5, 6, 8, 9, 10, 11, 13]]] . at "X"
|
||||
col.take (While (x-> x%2 == 1)) . to_vector . should_equal [1, 3, 5]
|
||||
col.drop (While (x-> x%2 == 1)) . to_vector . should_equal [6, 8, 9, 10, 11, 13]
|
||||
col.take (..While (x-> x%2 == 1)) . to_vector . should_equal [1, 3, 5]
|
||||
col.drop (..While (x-> x%2 == 1)) . to_vector . should_equal [6, 8, 9, 10, 11, 13]
|
||||
|
||||
three_table = table_builder [["X", [1, 2, 3]]]
|
||||
three = three_table . at "X"
|
||||
empty = three_table.remove_all_rows . at "X"
|
||||
three.take (While (_ > 10)) . should_equal empty
|
||||
three.take (While (_ < 10)) . should_equal three
|
||||
three.take (..While (_ > 10)) . should_equal empty
|
||||
three.take (..While (_ < 10)) . should_equal three
|
||||
|
||||
three.drop (While (_ > 10)) . should_equal three
|
||||
three.drop (While (_ < 10)) . should_equal empty
|
||||
three.drop (..While (_ > 10)) . should_equal three
|
||||
three.drop (..While (_ < 10)) . should_equal empty
|
||||
|
||||
group_builder.specify "should gracefully handle missing constructor arguments" <|
|
||||
c = table_builder [["X", [1, 2, 3]]] . at "X"
|
||||
Test.expect_panic Type_Error <| c.take "FOO"
|
||||
Test.expect_panic Type_Error <| c.drop "FOO"
|
||||
|
||||
r1 = c.take (Index_Sub_Range.While)
|
||||
r1 = c.take (..While)
|
||||
r1.should_fail_with Missing_Argument
|
||||
r1.catch.to_display_text . should_contain "Provide a value for the argument `predicate`."
|
||||
|
||||
r1b = c.take (..By_Index)
|
||||
r1b.should_fail_with Missing_Argument
|
||||
r1b.catch.to_display_text . should_contain "Provide a value for the argument `indexes`."
|
||||
|
||||
group_builder.specify "unordered table" <|
|
||||
unordered_table =
|
||||
col1 = ["alpha", [1,2,3,4,5,6,7,8]]
|
||||
|
@ -698,7 +698,7 @@ add_postgres_specs suite_builder create_connection_fn db_name =
|
||||
agg_in_memory_table.select_into_database_table default_connection.get (Name_Generator.random_name "Agg1") primary_key=Nothing temporary=True
|
||||
|
||||
empty_agg_table_fn = _->
|
||||
(agg_in_memory_table.take (First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
(agg_in_memory_table.take (..First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
|
||||
setup = Common_Table_Operations.Main.Test_Setup.Config prefix agg_table_fn empty_agg_table_fn table_builder materialize is_database=True test_selection=common_selection aggregate_test_selection=aggregate_selection create_connection_func=create_connection_fn light_table_builder=light_table_builder
|
||||
|
||||
|
@ -348,7 +348,7 @@ sqlite_spec suite_builder prefix create_connection_func =
|
||||
agg_in_memory_table.select_into_database_table default_connection.get (Name_Generator.random_name "Agg1") primary_key=Nothing temporary=True
|
||||
|
||||
empty_agg_table_fn = _ ->
|
||||
(agg_in_memory_table.take (First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
(agg_in_memory_table.take (..First 0)).select_into_database_table default_connection.get (Name_Generator.random_name "Agg_Empty") primary_key=Nothing temporary=True
|
||||
|
||||
setup = Common_Table_Operations.Main.Test_Setup.Config prefix agg_table_fn empty_agg_table_fn table_builder materialize is_database=True test_selection=common_selection aggregate_test_selection=aggregate_selection create_connection_func=create_connection_func light_table_builder=light_table_builder
|
||||
sqlite_specific_spec suite_builder prefix create_connection_func setup
|
||||
|
@ -21,7 +21,7 @@ type Data
|
||||
|
||||
setup =
|
||||
v1 = [0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 10, 10, 10, 10, 11, 14, 17, 19]
|
||||
v1_shuffled = v1.take (Index_Sub_Range.Sample v1.length)
|
||||
v1_shuffled = v1.take (..Sample v1.length)
|
||||
Data.Value (make_index v1_shuffled)
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from Standard.Base import all hiding First, Last
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Table import Table
|
||||
|
@ -43,9 +43,9 @@ add_specs suite_builder =
|
||||
expected_1 = Column.from_vector "Test" [1, 3, 5]
|
||||
expected_2 = Column.from_vector "Test" [1, 3, 5, 2, 4, 6]
|
||||
expected_3 = Column.from_vector "Test" []
|
||||
test_column.take (First 3) . to_vector . should_equal expected_1.to_vector
|
||||
test_column.take (First 7) . to_vector . should_equal expected_2.to_vector
|
||||
test_column.take (First 0) . to_vector . should_equal expected_3.to_vector
|
||||
test_column.take (..First 3) . to_vector . should_equal expected_1.to_vector
|
||||
test_column.take (..First 7) . to_vector . should_equal expected_2.to_vector
|
||||
test_column.take (..First 0) . to_vector . should_equal expected_3.to_vector
|
||||
|
||||
group_builder.specify "should be able to take the first n elements by Integer" <|
|
||||
expected_1 = Column.from_vector "Test" [1, 3, 5]
|
||||
@ -59,9 +59,9 @@ add_specs suite_builder =
|
||||
expected_1 = Column.from_vector "Test" [2, 4, 6]
|
||||
expected_2 = Column.from_vector "Test" [1, 3, 5, 2, 4, 6]
|
||||
expected_3 = Column.from_vector "Test" []
|
||||
test_column.take (Last 3) . to_vector . should_equal expected_1.to_vector
|
||||
test_column.take (Last 7) . to_vector . should_equal expected_2.to_vector
|
||||
test_column.take (Last 0) . to_vector . should_equal expected_3.to_vector
|
||||
test_column.take (..Last 3) . to_vector . should_equal expected_1.to_vector
|
||||
test_column.take (..Last 7) . to_vector . should_equal expected_2.to_vector
|
||||
test_column.take (..Last 0) . to_vector . should_equal expected_3.to_vector
|
||||
|
||||
group_builder.specify "should be able to get the first element" <|
|
||||
test_column.first . should_equal 1
|
||||
|
@ -464,20 +464,20 @@ add_specs suite_builder =
|
||||
c_3 = ['col3', [False, True, Nothing]]
|
||||
t_1 = Table.new [i_1, c_1, c_2, c_3]
|
||||
|
||||
t_1.take (First 10) . at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector)
|
||||
t_1.take (..First 10) . at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector)
|
||||
t_1.take 10 . at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector)
|
||||
|
||||
t_2 = t_1.take (First 2)
|
||||
t_2.at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector . take (First 2))
|
||||
t_2.at 'col2' . to_vector . should_equal (t_1.at 'col2' . to_vector . take (First 2))
|
||||
t_2.at 'col3' . to_vector . should_equal (t_1.at 'col3' . to_vector . take (First 2))
|
||||
t_2 = t_1.take (..First 2)
|
||||
t_2.at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector . take (..First 2))
|
||||
t_2.at 'col2' . to_vector . should_equal (t_1.at 'col2' . to_vector . take (..First 2))
|
||||
t_2.at 'col3' . to_vector . should_equal (t_1.at 'col3' . to_vector . take (..First 2))
|
||||
|
||||
t_3 = t_1.take 2
|
||||
t_3.at 'col' . to_vector . should_equal (t_1.at 'col' . to_vector . take 2)
|
||||
t_3.at 'col2' . to_vector . should_equal (t_1.at 'col2' . to_vector . take 2)
|
||||
t_3.at 'col3' . to_vector . should_equal (t_1.at 'col3' . to_vector . take 2)
|
||||
|
||||
t_1.at 'col' . take (First 2) . to_vector . should_equal (t_1.at 'col' . to_vector . take (First 2))
|
||||
t_1.at 'col' . take (..First 2) . to_vector . should_equal (t_1.at 'col' . to_vector . take (..First 2))
|
||||
t_1.at 'col' . take 2 . to_vector . should_equal (t_1.at 'col' . to_vector . take 2)
|
||||
|
||||
group_builder.specify "should allow taking the last n rows" <|
|
||||
@ -487,35 +487,35 @@ add_specs suite_builder =
|
||||
c_3 = ['col3', [False, True, Nothing]]
|
||||
t_1 = Table.new [i_1, c_1, c_2, c_3]
|
||||
|
||||
t_1.take (Last 10) . at 'col1' . to_vector . should_equal (t_1.at 'col1' . to_vector)
|
||||
t_1.take (..Last 10) . at 'col1' . to_vector . should_equal (t_1.at 'col1' . to_vector)
|
||||
|
||||
t_2 = t_1.take (Last 2)
|
||||
t_2.at 'col1' . to_vector . should_equal (t_1.at 'col1' . to_vector . take (Last 2))
|
||||
t_2.at 'col2' . to_vector . should_equal (t_1.at 'col2' . to_vector . take (Last 2))
|
||||
t_2.at 'col3' . to_vector . should_equal (t_1.at 'col3' . to_vector . take (Last 2))
|
||||
t_2 = t_1.take (..Last 2)
|
||||
t_2.at 'col1' . to_vector . should_equal (t_1.at 'col1' . to_vector . take (..Last 2))
|
||||
t_2.at 'col2' . to_vector . should_equal (t_1.at 'col2' . to_vector . take (..Last 2))
|
||||
t_2.at 'col3' . to_vector . should_equal (t_1.at 'col3' . to_vector . take (..Last 2))
|
||||
|
||||
t_1.at 'col1' . take (Last 2) . to_vector . should_equal (t_1.at 'col1' . to_vector . take (Last 2))
|
||||
t_1.at 'col1' . take (..Last 2) . to_vector . should_equal (t_1.at 'col1' . to_vector . take (..Last 2))
|
||||
|
||||
group_builder.specify "should allow taking/dropping a prefix of rows that satisfy a predicate" <|
|
||||
t1 = Table.new [["X", [1, 2, 3, 4, 5, 5]], ["Y", [9, 8, 7, 2, 10, 5]]]
|
||||
|
||||
t2 = t1.take (Index_Sub_Range.While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
t2 = t1.take (..While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
t2.at "X" . to_vector . should_equal [1, 2, 3]
|
||||
t2.at "Y" . to_vector . should_equal [9, 8, 7]
|
||||
|
||||
t3 = t1.drop (Index_Sub_Range.While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
t3 = t1.drop (..While row-> row.to_vector.compute Statistic.Sum == 10)
|
||||
t3.at "X" . to_vector . should_equal [4, 5, 5]
|
||||
t3.at "Y" . to_vector . should_equal [2, 10, 5]
|
||||
|
||||
t4 = t1.take (Index_Sub_Range.While row-> row.at "X" < 3)
|
||||
t4 = t1.take (..While row-> row.at "X" < 3)
|
||||
t4.at "X" . to_vector . should_equal [1, 2]
|
||||
t4.at "Y" . to_vector . should_equal [9, 8]
|
||||
|
||||
t5 = t1.drop (Index_Sub_Range.While row-> row.at 1 > 3)
|
||||
t5 = t1.drop (..While row-> row.at 1 > 3)
|
||||
t5.at "X" . to_vector . should_equal [4, 5, 5]
|
||||
t5.at "Y" . to_vector . should_equal [2, 10, 5]
|
||||
|
||||
t6 = t1.take (Index_Sub_Range.While row-> row.at "X" > 1)
|
||||
t6 = t1.take (..While row-> row.at "X" > 1)
|
||||
t6.at "X" . to_vector . should_equal []
|
||||
t6.at "Y" . to_vector . should_equal []
|
||||
|
||||
|
@ -107,7 +107,7 @@ add_specs suite_builder =
|
||||
data = json.get 'data'
|
||||
data.should_be_a Vector
|
||||
data.length . should_equal 10
|
||||
(data.take (First 3) . sort on=(_.get "x")).to_text . should_equal '[{"x":0,"y":225}, {"x":15,"y":0}, {"x":29,"y":196}]'
|
||||
(data.take (..First 3) . sort on=(_.get "x")).to_text . should_equal '[{"x":0,"y":225}, {"x":15,"y":0}, {"x":29,"y":196}]'
|
||||
|
||||
group_builder.specify "filter the elements" <|
|
||||
vector = [0,10,20,30]
|
||||
|
@ -28,7 +28,7 @@ main =
|
||||
operator19 = operator17.remove_columns ['Approach']
|
||||
operator21 = operator19.set '"circle"' "Shape"
|
||||
operator20 = operator21.rename_columns ['x' ]
|
||||
operator22 = operator18.drop (First 40)
|
||||
operator22 = operator18.drop (..First 40)
|
||||
operator23 = operator22.select_columns ['Approach']
|
||||
operator24 = operator23.distinct ['Approach']
|
||||
operator26 = operator24.at 0
|
||||
|
Loading…
Reference in New Issue
Block a user