blob: e49455066c7779187bf7799a7e9e145f238005ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
:actor Main
:new (env)
Spec.Process.run(env, [
Spec.Run(AdditionSpec).new(env)
])
:class AdditionSpec
:is Spec
:const describes: "Addition"
:: Return the number 2 (written in hex, just for fun).
:const _two U64'val: 0x02
:it "adds two twos"
assert: @_two + '\x02' == 4
:: Raise an error if the argument is positive.
:fun non add_overflow!(a U64'val, b U64'val): a +! b
:it "can error on overflow"
integers Array(U64)'val = [99, 100, 101]
// Check addition overflow for various pairs of addends.
assert error: add_overflow!(U64.max_value, 1)
assert no_error: add_overflow!(U64.max_value, 0)
assert no_error: add_overflow!(integers[0]!, 1)
// Print a bit of extra information using string interpolation.
@env.out.print("The first integer is \(integers[0]!)")
|