1 | #!bin/ysh
|
2 |
|
3 | use $LIB_YSH/math.ysh --pick max min abs
|
4 |
|
5 | # Change to 'use'?
|
6 | source $LIB_OSH/byo-server.sh
|
7 |
|
8 | proc test-identity {
|
9 |
|
10 | assert [42 === math.identity(42)]
|
11 |
|
12 | var mylist = [3, 4, 5]
|
13 | assert [mylist === math.identity(mylist)]
|
14 |
|
15 | var mydict = {foo: 'bar'}
|
16 | assert [mydict === math.identity(mydict)]
|
17 | }
|
18 |
|
19 | proc test-max {
|
20 | assert [2 === max(1, 2)]
|
21 | assert [3 === max([1, 2, 3])]
|
22 |
|
23 | try { call max([]) }
|
24 | assert [3 === _error.code]
|
25 |
|
26 | try { call max(1, 2) }
|
27 | assert [0 === _error.code]
|
28 |
|
29 | try { call max(1, 2, 3) }
|
30 | assert [3 === _error.code]
|
31 |
|
32 | try { call max() }
|
33 | assert [3 === _error.code]
|
34 | }
|
35 |
|
36 | proc test-min {
|
37 | assert [2 === min(2, 3)]
|
38 | assert [1 === min([1, 2, 3])]
|
39 |
|
40 | try { call min([]) }
|
41 | assert [3 === _error.code]
|
42 |
|
43 | try { call min(2, 3) }
|
44 | assert [0 === _error.code]
|
45 |
|
46 | try { call min(1, 2, 3) }
|
47 | assert [3 === _error.code]
|
48 |
|
49 | try { call min() }
|
50 | assert [3 === _error.code]
|
51 | }
|
52 |
|
53 | proc test-abs {
|
54 | assert [1 === abs(-1)]
|
55 | assert [0 === abs(0)]
|
56 | assert [1 === abs(1)]
|
57 | assert [42 === abs(42)]
|
58 | assert [42 === abs(-42)]
|
59 | }
|
60 |
|
61 | if is-main {
|
62 | byo-maybe-run
|
63 | }
|
64 |
|