fork/numbat

git clone https://git.julia.blue/fork/numbat

David PeterAdd str_replace and tests92e4188

v1.7.0
1.8 KiB74 linesraw
1# unit_of
2
3assert_eq(unit_of(0),            1)
4
5assert_eq(unit_of(1),            1)
6assert_eq(unit_of(1.2345),       1)
7
8assert_eq(unit_of(1 m),          m)
9assert_eq(unit_of(1.2345 m),     m)
10
11assert_eq(unit_of(1 m^2/s),      m^2/s)
12assert_eq(unit_of(1.2345 m^2/s), m^2/s)
13
14# value_of
15
16assert_eq(value_of(0),            0)
17
18assert_eq(value_of(1),            1)
19assert_eq(value_of(1.2345),       1.2345)
20
21assert_eq(value_of(1 m),          1)
22assert_eq(value_of(1.2345 m),     1.2345)
23
24assert_eq(value_of(1 m^2/s),      1)
25assert_eq(value_of(1.2345 m^2/s), 1.2345)
26
27# hypot
28
29assert_eq(hypot2(3, 4), 5)
30assert_eq(hypot2(3 m, 4 m), 5 m)
31
32assert_eq(hypot3(8, 9, 12), 17)
33assert_eq(hypot3(8 m, 9 m, 12 m), 17 m)
34
35# trigonometry_extra
36
37assert_eq(cot(0.3), 3.2327281, 1e-5)
38assert_eq(acot(0.3), 1.2793395, 1e-5)
39
40assert_eq(coth(0.3), 3.4327384, 1e-5)
41assert_eq(acoth(1.3), 1.018441, 1e-5)
42
43assert_eq(secant(0.3), 1.0467516, 1e-5)
44assert_eq(arcsecant(1.3), 0.693160, 1e-5)
45
46assert_eq(csc(0.3), 3.3838634, 1e-5)
47assert_eq(acsc(1.3), 0.877636, 1e-5)
48
49assert_eq(sech(1.3), 0.507379, 1e-5)
50assert_eq(asech(0.3), 1.873820, 1e-5)
51
52assert_eq(csch(0.3), 3.283853, 1e-5)
53assert_eq(acsch(0.3), 1.918896, 1e-5)
54
55# strings
56
57assert_eq(str_length(""), 0)
58assert_eq(str_length("foo"), 3)
59
60assert(str_slice("hello world", 0, 5) == "hello")
61assert(str_slice("hello world", 6, 11) == "world")
62assert(str_slice("hello world", 0, 0) == "")
63assert(str_slice("hello world", 0, 100) == "")
64
65assert(str_append("foo", "bar") == "foobar")
66
67assert(str_contains("hello world", "hello"))
68assert(str_contains("hello world", "world"))
69assert(str_contains("hello world", "HELLO") == false)
70
71assert(str_replace("hello world", "hello", "HEY") == "HEY world")
72assert(str_replace("xxx", "x", "yY") == "yYyYyY")
73
74assert(str_repeat("xy", 3) == "xyxyxy")