Skip to content

Commit

Permalink
Adds changes based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Nov 21, 2024
1 parent b881e19 commit 5c78033
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 34 deletions.
17 changes: 17 additions & 0 deletions conformance/system_macros/delta.ion
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@
"a numeric string"
(text "(:delta 1 '''3''' 2)")
(signals "invalid argument")))

// Demonstrations of some interesting things you can do with delta.

(ion_1_1 "delta and repeat can be combined to generate"
(mactab $ion_encoding (macro from_x_count_n_by_step (x n step) (.delta (.. (%x) (.repeat (%n) (%step))))))
(then "an increasing sequence" (text "(:from_x_count_n_by_step 0 10 1)") (produces 0 1 2 3 4 5 6 7 8 9 10))
(then "a count-by-twos sequence" (text "(:from_x_count_n_by_step 0 10 2)") (produces 0 2 4 6 8 10 12 14 16 18 20))
(then "a decreasing sequence" (text "(:from_x_count_n_by_step 5 10 -1)") (produces 5 4 3 2 1 0 -1 -2 -3 -4 -5)))

(ion_1_1 "it is possible to create a delta of deltas encoding"
// See, for example
// https://www.timescale.com/blog/time-series-compression-algorithms-explained/#delta-of-delta-encoding
(mactab $ion_encoding
(macro delta_of_deltas (flex_int::init dod*) (.delta (.. (%init) (.delta (%dod)))))
(macro rle (flex_uint::run_length flex_int::value) (.repeat (%run_length) (%value))))
(text "(:delta_of_deltas 52 (:: -1 (:rle 10 0) 1 (:rle 5 0) 1 (:rle 5 0)))")
(produces 52 51 50 49 48 47 46 45 44 43 42 41 41 41 41 41 41 41 42 43 44 45 46 47))
90 changes: 56 additions & 34 deletions conformance/system_macros/sum.ion
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,74 @@

(ion_1_1 "sum can be invoked"
(each "in text with an unqualified macro name"
(text "(:sum)")
(text "(:sum 0 0)")
"in text with an unqualified macro address"
(text "(:20)")
(text "(:20 0 0)")
"in text with a qualified macro name"
(text "(:$ion::sum)")
(text "(:$ion::sum 0 0)")
"in text with a qualified macro address"
(text "(:$ion::20)")
(text "(:$ion::20 0 0)")
"in binary with a system macro address"
(binary "EF 14 00")
(binary "EF 14 60 60")
"in binary with a user macro address"
(binary "14 00")
(binary "14 60 60")
(produces 0)))

(ion_1_1 "sum produces a single value that is the sum of"
(each "zero arguments"
(binary "EF 14 00")
(text "(:sum)")
(text "(:sum (::))")
(produces 0))
(then "one argument"
(binary "EF 14 01 03")
(text "(:sum 1)")
(produces 1))
(each "multiple arguments"
(binary "EF 14 02 09 61 08 61 07")
(text "(:sum 1 2 3 4 5)")
(text "(:sum 0 15)")
(text "(:sum 10 10 -2 -3)")
// Annotations are silently dropped
(text "(:sum a::1 b::2 c::3 d::4 e::5)")
(produces 15)))
(ion_1_1 "sum produces a single, unannotated integer that is the sum of"
(each "two integers"
(text "(:sum -1 4)")
(text "(:sum 0 3)")
(text "(:sum 1 2)")
(text "(:sum 2 1)")
(text "(:sum 3 0)")
(text "(:sum 4 -1)")
"annotated integers"
(text "(:sum a::1 2)")
(text "(:sum 1 b::2)")
(text "(:sum a::1 b::2)")
// Values that produce an integer
(text "(:sum (:values 1) 2)")
(text "(:sum 1 (:values 2))")
// ...including other sums
(text "(:sum (:sum 1 1) 1)")
(text "(:sum 1 (:sum 1 1))")
(produces 3)))

(ion_1_1 "sum is commutative"
(each (text "(:sum 1 0)") (text "(:sum 0 1)") (produces 1))
(each (text "(:sum -1 0)") (text "(:sum 0 -1)") (produces -1))
(each (text "(:sum -1 1)") (text "(:sum 1 -1)") (produces 0))
(each (text "(:sum 3 7)") (text "(:sum 7 3)") (produces 10))
(each (text "(:sum -3 -5)") (text "(:sum -5 -3)") (produces -8))
(each (text "(:sum -2 4)") (text "(:sum 4 -2)") (produces 2)))

(ion_1_1 "arguments may not be"
(each "any null"
(text "(:sum 1 null 2)")
(text "(:sum 1 null.int 2)")
(text "(:sum 1 null.float 2)")
(text "(:sum 1 null.decimal 2)")
(text "(:sum 1 null)")
(text "(:sum 1 null.int)")
(text "(:sum 1 null.float)")
(text "(:sum 1 null.decimal)")
(text "(:sum null 2)")
(text "(:sum null.int 2)")
(text "(:sum null.float 2)")
(text "(:sum null.decimal 2)")
"a float"
(text "(:sum 1 3e1 2)")
(text "(:sum 1 3e1)")
(text "(:sum 3e1 2)")
"a decimal"
(text "(:sum 1 3d1 2)")
(text "(:sum 1 3d1)")
(text "(:sum 3d1 2)")
"a list of numbers"
(text "(:sum 1 [3, 4, 5] 2)")
(text "(:sum 1 [3])")
(text "(:sum [3] 2)")
(text "(:sum [1, 2])")
"a sexp of numbers"
(text "(:sum 1 (3 4 5) 2)")
"a numeric string"
(text "(:sum 1 '''3''' 2)")
(text "(:sum 1 (3))")
(text "(:sum (3) 2)")
(text "(:sum (1 2))")
"a numeric text value"
(text '''(:sum 1 "3")''')
(text '''(:sum 1 '3')''')
(text '''(:sum "3" 2)''')
(text '''(:sum '3' 2)''')
(signals "invalid argument")))

0 comments on commit 5c78033

Please sign in to comment.