prelude_tests.nbt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # unit_of
  2. assert_eq(unit_of(0), 1)
  3. assert_eq(unit_of(1), 1)
  4. assert_eq(unit_of(1.2345), 1)
  5. assert_eq(unit_of(1 m), m)
  6. assert_eq(unit_of(1.2345 m), m)
  7. assert_eq(unit_of(1 m^2/s), m^2/s)
  8. assert_eq(unit_of(1.2345 m^2/s), m^2/s)
  9. # value_of
  10. assert_eq(value_of(0), 0)
  11. assert_eq(value_of(1), 1)
  12. assert_eq(value_of(1.2345), 1.2345)
  13. assert_eq(value_of(1 m), 1)
  14. assert_eq(value_of(1.2345 m), 1.2345)
  15. assert_eq(value_of(1 m^2/s), 1)
  16. assert_eq(value_of(1.2345 m^2/s), 1.2345)
  17. # hypot
  18. assert_eq(hypot2(3, 4), 5)
  19. assert_eq(hypot2(3 m, 4 m), 5 m)
  20. assert_eq(hypot3(8, 9, 12), 17)
  21. assert_eq(hypot3(8 m, 9 m, 12 m), 17 m)
  22. # trigonometry_extra
  23. assert_eq(cot(0.3), 3.2327281, 1e-5)
  24. assert_eq(acot(0.3), 1.2793395, 1e-5)
  25. assert_eq(coth(0.3), 3.4327384, 1e-5)
  26. assert_eq(acoth(1.3), 1.018441, 1e-5)
  27. assert_eq(secant(0.3), 1.0467516, 1e-5)
  28. assert_eq(arcsecant(1.3), 0.693160, 1e-5)
  29. assert_eq(csc(0.3), 3.3838634, 1e-5)
  30. assert_eq(acsc(1.3), 0.877636, 1e-5)
  31. assert_eq(sech(1.3), 0.507379, 1e-5)
  32. assert_eq(asech(0.3), 1.873820, 1e-5)
  33. assert_eq(csch(0.3), 3.283853, 1e-5)
  34. assert_eq(acsch(0.3), 1.918896, 1e-5)
  35. # strings
  36. assert_eq(str_length(""), 0)
  37. assert_eq(str_length("foo"), 3)
  38. assert(str_slice("hello world", 0, 5) == "hello")
  39. assert(str_slice("hello world", 6, 11) == "world")
  40. assert(str_slice("hello world", 0, 0) == "")
  41. assert(str_slice("hello world", 0, 100) == "")
  42. assert(str_append("foo", "bar") == "foobar")
  43. assert(str_contains("hello world", "hello"))
  44. assert(str_contains("hello world", "world"))
  45. assert(str_contains("hello world", "HELLO") == false)
  46. assert(str_replace("hello world", "hello", "HEY") == "HEY world")
  47. assert(str_replace("xxx", "x", "yY") == "yYyYyY")
  48. assert(str_replace("a b", " ", " ") == "a b")
  49. assert(str_repeat("xy", 3) == "xyxyxy")
  50. assert((0b0 -> bin) == "0b0")
  51. assert((0b1 -> bin) == "0b1")
  52. assert((0b10 -> bin) == "0b10")
  53. assert((0b11 -> bin) == "0b11")
  54. assert((0b10101010101010101010101010101010 -> bin) == "0b10101010101010101010101010101010")
  55. assert((-0b11110000 -> bin) == "-0b11110000")
  56. assert((0o0 -> oct) == "0o0")
  57. assert((0o1 -> oct) == "0o1")
  58. assert((0o7 -> oct) == "0o7")
  59. assert((0o10 -> oct) == "0o10")
  60. assert((0o77 -> oct) == "0o77")
  61. assert((0o12345670 -> oct) == "0o12345670")
  62. assert((-0o12345670 -> oct) == "-0o12345670")
  63. assert((0x0 -> hex) == "0x0")
  64. assert((0x1 -> hex) == "0x1")
  65. assert((0x9 -> hex) == "0x9")
  66. assert((0xa -> hex) == "0xa")
  67. assert((0xf -> hex) == "0xf")
  68. assert((0xabc1234567890 -> hex) == "0xabc1234567890")
  69. assert((-0xc0ffee -> hex) == "-0xc0ffee")