fork/numbat
git clone https://git.julia.blue/fork/numbat
02e8faa
master
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") 73assert(str_replace("a b", " ", " ") == "a b") 74 75assert(str_repeat("xy", 3) == "xyxyxy") 76 77assert((0b0 -> bin) == "0b0") 78assert((0b1 -> bin) == "0b1") 79assert((0b10 -> bin) == "0b10") 80assert((0b11 -> bin) == "0b11") 81assert((0b10101010101010101010101010101010 -> bin) == "0b10101010101010101010101010101010") 82assert((-0b11110000 -> bin) == "-0b11110000") 83 84assert((0o0 -> oct) == "0o0") 85assert((0o1 -> oct) == "0o1") 86assert((0o7 -> oct) == "0o7") 87assert((0o10 -> oct) == "0o10") 88assert((0o77 -> oct) == "0o77") 89assert((0o12345670 -> oct) == "0o12345670") 90assert((-0o12345670 -> oct) == "-0o12345670") 91 92assert((0x0 -> hex) == "0x0") 93assert((0x1 -> hex) == "0x1") 94assert((0x9 -> hex) == "0x9") 95assert((0xa -> hex) == "0xa") 96assert((0xf -> hex) == "0xf") 97assert((0xabc1234567890 -> hex) == "0xabc1234567890") 98assert((-0xc0ffee -> hex) == "-0xc0ffee")