diff --git a/IO.ark b/IO.ark new file mode 100644 index 0000000..e3338ed --- /dev/null +++ b/IO.ark @@ -0,0 +1,65 @@ +# @brief Write content to a file. Return nil +# @param filename path to the file to write to (will be overwritten if it exists) +# @param content can be any valid ArkScript value +# =begin +# (io:writeFile "hello.json" "{\"key\": 12}") +# =end +# @author https://github.com/SuperFola +(let writeFile (fun (_name _content) (builtin__io:writeFile _name _content))) + +# @brief Append content to a file. Return nil +# @param filename path to the file to append to +# @param content can be any valid ArkScript value +# =begin +# (io:writeFile "hello.json" "{\"key\": 12}") +# =end +# @author https://github.com/SuperFola +(let appendToFile (fun (_name _content) (builtin__io:appendToFile _name _content))) + +# @brief Read the content from a file as a String +# @param filename the path of the file to read +# =begin +# (io:readFile "hello.json") +# =end +# @author https://github.com/SuperFola +(let readFile (fun (_name) (builtin__io:readFile _name))) + +# @brief Check if a file exists, return True or False +# @param filename the path of the file +# =begin +# (io:fileExists? "hello.json") +# =end +# @author https://github.com/SuperFola +(let fileExists? (fun (_name) (builtin__io:fileExists? _name))) + +# @brief List files in a folder, as a List of String +# @param path A directory +# =begin +# (io:listFiles "/tmp/hello") +# =end +# @author https://github.com/SuperFola +(let listFiles (fun (_path) (builtin__io:listFiles _path))) + +# @brief Check if a path represents a directory +# @param path A directory +# =begin +# (io:dir? "/tmp/hello") +# =end +# @author https://github.com/SuperFola +(let dir? (fun (_path) (builtin__io:dir? _path))) + +# @brief Create a directory +# @param path A directory +# =begin +# (io:makeDir "/tmp/myDir") +# =end +# @author https://github.com/SuperFola +(let makeDir (fun (_path) (builtin__io:makeDir _path))) + +# @brief Delete file +# @param filename path to file +# =begin +# (io:removeFile "/tmp/test.ark") +# =end +# @author https://github.com/SuperFola +(let removeFile (fun (_path) (builtin__io:removeFile _path))) diff --git a/List.ark b/List.ark index 4ebe8c5..e58bd04 100644 --- a/List.ark +++ b/List.ark @@ -1,3 +1,64 @@ +# @brief Reverse a given list and return a new one +# @details The original list is not modified +# @param list the list to reverse +# =begin +# (list:reverse [1 2 3]) # [3 2 1] +# =end +# @author https://github.com/SuperFola +(let reverse (fun (_L) (builtin__list:reverse _L))) + +# @brief Search an element in a List +# @details The original list is not modified +# @param list the List to search in +# @param value the element to search +# =begin +# (list:find [1 2 3] 1) # 0 +# (list:find [1 2 3] 0) # -1 +# =end +# @author https://github.com/SuperFola +(let find (fun (_L _x) (builtin__list:find _L _x))) + +# @brief Get a slice from a List +# @details The original list is not modified +# @param list the list to reverse +# @param start included, must be positive +# @param end not included, must be positive and smaller than the list +# @param step must be greater than 0 +# =begin +# (list:slice [1 2 3 4 5] 1 4 2) # [2 4] +# =end +# @author https://github.com/SuperFola +(let slice (fun (_L _start _end _step) (builtin__list:slice _L _start _end _step))) + +# @brief Sort a List and return a new one +# @details The original list is not modified +# @param list the list to sort +# =begin +# (list:sort [4 2 3]) # [1 2 4] +# =end +# @author https://github.com/SuperFola +(let sort (fun (_L) (builtin__list:sort _L))) + +# @brief Generate a List of n copies of an element +# @param count the number of copies +# @param value the element to copy +# =begin +# (list:fill 4 nil) # [nil nil nil nil] +# =end +# @author https://github.com/SuperFola +(let fill (fun (_val _count) (builtin__list:fill _val _count))) + +# @brief Modify a given list and return a new one +# @details The original list is not modified +# @param list the list to modify +# @param index the index of the element to modify +# @param value the new element +# =begin +# (list:setAt [1 2 3] 0 5) # [5 2 3] +# =end +# @author https://github.com/SuperFola +(let setAt (fun (_L _index _x) (builtin__list:setAt _L _index _x))) + # @brief Iterate over a given list and run a given function on every element. # @param _L the list to iterate over # @param _func the function to call on each element diff --git a/Math.ark b/Math.ark index f266af0..08a4e22 100644 --- a/Math.ark +++ b/Math.ark @@ -1,3 +1,163 @@ +# @brief Calculate e^number +# @param value the Number +# =begin +# (math:exp 1) # 2.7182... +# =end +# @author https://github.com/SuperFola +(let exp (fun (_x) (builtin__math:exp _x))) + +# @brief Calculate the logarithm of a number +# @param value the Number +# =begin +# (math:ln 1) # 0 +# =end +# @author https://github.com/SuperFola +(let ln (fun (_x) (builtin__math:ln _x))) + +# @brief Get the smallest possible integer greater than the number +# @param value the Number +# =begin +# (math:ceil 0.2) # 1 +# =end +# @author https://github.com/SuperFola +(let ceil (fun (_x) (builtin__math:ceil _x))) + +# @brief Get the smallest possible integer equal to the given number +# @param value the Number +# =begin +# (math:floor 1.7) # 1 +# =end +# @author https://github.com/SuperFola +(let floor (fun (_x) (builtin__math:floor _x))) + +# @brief Get the smallest possible integer equal to or greater than the given number +# @param value the Number +# =begin +# (math:round 0.2) # 0 +# (math:round 0.6) # 1 +# =end +# @author https://github.com/SuperFola +(let round (fun (_x) (builtin__math:round _x))) + +# @brief Check if a Number is NaN +# @param value the Number +# =begin +# (math:NaN? 2) # false +# (math:NaN? nan) # true +# =end +# @author https://github.com/SuperFola +(let NaN? (fun (_x) (builtin__math:NaN? _x))) + +# @brief Check if a Number if Inf +# @param value the Number +# =begin +# (math:Inf? 1) # false +# (math:Inf? nan) # false +# =end +# @author https://github.com/SuperFola +(let Inf? (fun (_x) (builtin__math:Inf? _x))) + +# @brief Calculate the cosinus of a number +# @param value the Number (radians) +# =begin +# (math:cos 0) # 1 +# (math:cos math:pi) # -1 +# =end +# @author https://github.com/SuperFola +(let cos (fun (_x) (builtin__math:cos _x))) + +# @brief Calculate the sinus of a number +# @param value the Number (radians) +# =begin +# (math:sin 0) # 0 +# (math:cos (/ math:pi 2)) # 1 +# =end +# @author https://github.com/SuperFola +(let sin (fun (_x) (builtin__math:sin _x))) + +# @brief Calculate the tangent of a number +# @param value the Number (radians) +# =begin +# (math:tan 0) # 0 +# (math:cos (/ math:pi 4)) # 1 +# =end +# @author https://github.com/SuperFola +(let tan (fun (_x) (builtin__math:tan _x))) + +# @brief Calculate the arc cosinus of a number +# @param value the Number +# =begin +# (math:arccos 1) # 0 +# =end +# @author https://github.com/SuperFola +(let arccos (fun (_x) (builtin__math:arccos _x))) + +# @brief Calculate the arc sinus of a number +# @param value the Number +# =begin +# (math:arcsin 1) # 1.570796326794897 (/ math:pi 2) +# =end +# @author https://github.com/SuperFola +(let arcsin (fun (_x) (builtin__math:arcsin _x))) + +# @brief Calculate the arc tangent of a number +# @param value the Number +# =begin +# (math:arctan 0) # 0 +# =end +# @author https://github.com/SuperFola +(let arctan (fun (_x) (builtin__math:arctan _x))) + +# @brief Calculate the hyperbolic cosinus of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let cosh (fun (_x) (builtin__math:cosh _x))) + +# @brief Calculate the hyperbolic sinus of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let sinh (fun (_x) (builtin__math:sinh _x))) + +# @brief Calculate the hyperbolic tangent of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let tanh (fun (_x) (builtin__math:tanh _x))) + +# @brief Calculate the hyperbolic arc cosinus of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let acosh (fun (_x) (builtin__math:acosh _x))) + +# @brief Calculate the hyperbolic arc sinus of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let asinh (fun (_x) (builtin__math:asinh _x))) + +# @brief Calculate the hyperbolic arc tangent of a number +# @param value the Number +# @author https://github.com/Gryfenfer97 +(let atanh (fun (_x) (builtin__math:atanh _x))) + +# @brief Pi value (3.14159...) +# @author https://github.com/SuperFola +(let pi builtin__math:pi) + +# @brief E value (2.7182...) +# @author https://github.com/SuperFola +(let e builtin__math:e) + +# @brief Tau, the ratio of the circumference to the radius of a circle, which is equal to 2*pi (6.28318...) +# @author https://github.com/SuperFola +(let tau builtin__math:tau) + +# @brief Float infinite value +# @author https://github.com/SuperFola +(let Inf builtin__math:Inf) + +# @brief Float not-a-number value +# @author https://github.com/SuperFola +(let NaN builtin__math:NaN) + # @brief Return the absolute value of a number # @param _x the number to get the absolute value of # @author https://github.com/rstefanic @@ -39,13 +199,13 @@ # @param _x the number to pow # @param _a the exponent # @author https://github.com/SuperFola -(let pow (fun (_x _a) (math:exp (* _a (math:ln _x))))) +(let pow (fun (_x _a) (exp (* _a (ln _x))))) # @brief Get the square root of a number # @details Square roots can't be taken for negative numbers for obvious reasons. # @param _x the number # @author https://github.com/SuperFola -(let sqrt (fun (_x) (math:exp (* 0.5 (math:ln _x))))) +(let sqrt (fun (_x) (exp (* 0.5 (ln _x))))) # @brief Run the fibonacci function on a number # @param n the number @@ -71,7 +231,7 @@ (if (or (= 0 (mod n 2)) (= 1 n)) false { - (let k (math:ceil (+ 1 (sqrt n)))) + (let k (ceil (+ 1 (sqrt n)))) (mut i 3) (mut continue true) @@ -91,7 +251,7 @@ (assert (>= n 2) "divs: n must be greater or equal to 2") (mut i 2) (mut divisors [1]) - (let top (math:ceil (/ n 2))) + (let top (ceil (/ n 2))) (while (and (<= i top) (!= top n)) { (if (= (mod n i) 0) @@ -109,7 +269,7 @@ (let log (fun (x n) { (assert (> x 0) "log: x must be greater than 0") (assert (>= n 1) "log: n must be greater or equal to 1") - (math:round (/ (math:ln x) (math:ln n))) })) + (round (/ (ln x) (ln n))) })) # @brief Returns the logarithm base 2 of a number # @param x the number @@ -134,7 +294,7 @@ # =begin # (floordiv 14 6) # Returns 2 # =end -(let floordiv (fun (a b) (math:floor (/ a b)))) +(let floordiv (fun (a b) (floor (/ a b)))) # @brief Create a complex number # @param real the real part of the complex number diff --git a/String.ark b/String.ark index 68de50d..922dfad 100644 --- a/String.ark +++ b/String.ark @@ -1,3 +1,66 @@ +# @brief Search a substring in a given String +# @details The original String is not modified. Return -1 when not found +# @param string the String to search in +# @param substr the substring to search for +# =begin +# (string:find "hello world" "hello") # 0 +# (string:find "hello world" "aworld") # -1 +# =end +# @author https://github.com/SuperFola +(let find (fun (_str _sub) (builtin__string:find _str _sub))) + +# @brief Search a substring in a given String +# @details The original String is not modified. Return -1 when not found +# @param string the String to search in +# @param substr the substring to search for +# @param startIndex index to start searching from +# =begin +# (string:find "hello hello" "hello" 1) # 6 +# (string:find "hello world" "aworld" 0) # -1 +# =end +# @author https://github.com/SuperFola +(let findAfter (fun (_str _sub _after) (builtin__string:find _str _sub _after))) + +# @brief Remove a character from a String given an index +# @details The original String is not modified +# @param string the String to modify +# @param index the index of the character to remove (can be negative to search from the end) +# =begin +# (string:removeAt "hello world" 0) # "ello world" +# (string:removeAt "hello world" -1) # "hello worl" +# =end +# @author https://github.com/SuperFola +(let removeAt (fun (_str _index) (builtin__string:removeAt _str _index))) + +# @brief Get the ordinal of a given character +# @param char a String with a single UTF8 character +# =begin +# (string:ord "h") # 104 +# (string:ord "Ô") # 212 +# =end +# @author https://github.com/SuperFola +(let ord (fun (_str) (builtin__string:ord _str))) + +# @brief Create a character from an UTF8 codepoint +# @param codepoint an UTF8 codepoint (Number) +# =begin +# (string:chr 104) # "h" +# (string:chr 212) # "Ô" +# =end +# @author https://github.com/SuperFola +(let chr (fun (_str) (builtin__string:chr _str))) + +# @brief Modify a given string and return a new one +# @details The original string is not modified +# @param string the string to modify +# @param index the index of the element to modify +# @param value the new character +# =begin +# (string:setAt "hello" 1 "a") # "hallo" +# =end +# @author https://github.com/SuperFola +(let setAt (fun (_str _index _x) (builtin__string:setAt _str _index _x))) + # @brief Converts the given character to lowercase. # @param _string the string to make lowercase # @details The original string is left unmodified. @@ -17,8 +80,8 @@ (while (< _index (len text)) { (set _e (@ text _index)) - (if (in_range (string:ord _e) 65 90) - (set _e (string:chr (+ (string:ord _e) 32)))) + (if (in_range (ord _e) 65 90) + (set _e (chr (+ (ord _e) 32)))) (set _output (+ _output _e)) (set _index (+ _index 1)) }) _output })) @@ -42,8 +105,8 @@ (while (< _index (len _string)) { (set _e (@ _string _index)) - (if (in_range (string:ord _e) 97 122) - (set _e (string:chr (- (string:ord _e) 32)))) + (if (in_range (ord _e) 97 122) + (set _e (chr (- (ord _e) 32)))) (set _output (+ _output _e)) (set _index (+ _index 1)) }) _output })) @@ -107,7 +170,7 @@ # =end # @author https://github.com/Natendrtfm (let split (fun (_string _separator) { - (mut _at (string:find _string _separator)) + (mut _at (find _string _separator)) (let _seplen (len _separator)) (let _strlen (len _string)) (mut _output []) @@ -126,7 +189,7 @@ (append! _output _last) (set _last "") (set _i (+ _at _seplen)) - (set _at (string:find _string _separator _i)) + (set _at (findAfter _string _separator _i)) (if (= -1 _at) (set _at _strlen)) }) }) @@ -148,7 +211,7 @@ # =end (let replace (fun (_string _pattern _new) { (mut _out _string) - (mut _idx (string:find _out _pattern)) + (mut _idx (find _out _pattern)) (let _pattern_sz (len _pattern)) (while (!= -1 _idx) { @@ -156,7 +219,7 @@ (mut _next_segment (slice _out (+ _idx _pattern_sz) (- (len _out) (+ _idx _pattern_sz)))) (set _out (+ _first_segment _new _next_segment)) - (set _idx (string:find _next_segment _pattern)) + (set _idx (find _next_segment _pattern)) (if (!= -1 _idx) (set _idx (+ _idx (len _first_segment) (len _new)))) }) _out })) @@ -200,7 +263,7 @@ (while (< _index _line_count) { (let _current (@ _lines _index)) - (let _marker_pos (string:find _current "|")) + (let _marker_pos (find _current "|")) (if (= -1 _marker_pos) (set _output (+ _output _current)) (set _output (+ _output (slice _current (+ 1 _marker_pos) (len _current))))) diff --git a/Sys.ark b/Sys.ark new file mode 100644 index 0000000..61d4a7b --- /dev/null +++ b/Sys.ark @@ -0,0 +1,34 @@ +# @brief Execute a system specific command +# @details Return the output of the command as a String, or nil if it was disabled in the ArkScript build +# @param command the command to execute, as a String +# =begin +# (sys:exec "echo hello") +# =end +# @author https://github.com/SuperFola +(let exec (fun (_command) (builtin__sys:exec _command))) + +# @brief Sleep for a given duration (in milliseconds) +# @details Return nil +# @param duration a Number representing a duration +# =begin +# (sys:sleep 1000) # sleep for 1 second +# =end +# @author https://github.com/SuperFola +(let sleep (fun (_duration) (builtin__sys:sleep _duration))) + +# @brief Exit the program with the given exit code +# @details Any code after this function call won't be executed +# @param exitCode usually 0 for success and 1 for errors +# =begin +# (sys:exit 0) # halt the virtual machine with given exit code (success) +# =end +# @author https://github.com/SuperFola +(let exit (fun (_code) (builtin__sys:exit _code))) + +# @brief Platform on which the program is running (Windows, Mac OSX, Linux, FreeBSD, Unix, Other) +# @author https://github.com/SuperFola +(let platform builtin__sys:platform) + +# @brief Arguments given to the program when running it from the command line +# @author https://github.com/SuperFola +(let args builtin__sys:args) diff --git a/Testing.ark b/Testing.ark index b9a5205..f2e2217 100644 --- a/Testing.ark +++ b/Testing.ark @@ -71,11 +71,11 @@ # no newline, yet (puts _name) - (if (> _suite.passed 0) (puts (string:format " - {} ✅" _suite.passed))) + (if (> _suite.passed 0) (puts (format " - {} ✅" _suite.passed))) - (if (> _suite.failed 0) (puts (string:format ", {} ❌" _suite.failed))) + (if (> _suite.failed 0) (puts (format ", {} ❌" _suite.failed))) - (puts (string:format " in {:2.3f}ms\n" (* 1000 (- _end_time _start_time)))) + (puts (format " in {:2.3f}ms\n" (* 1000 (- _end_time _start_time)))) (mut _i 0) (let _failures_count (len _suite.failures)) @@ -124,7 +124,7 @@ (if (> _indent 0) (+ "{: <" (toString _indent) "}{}") "{}{}")) - (_suite.register_failure (string:format _fmt "" (@ _suite.cases _suite.case_pointer))) + (_suite.register_failure (format _fmt "" (@ _suite.cases _suite.case_pointer))) (_suite.update_case_ptr (+ 1 _suite.case_pointer)) }) })) # internal, do not use @@ -135,7 +135,7 @@ (let _test_desc (fun (_desc) (if (empty? _desc) "" - (string:format " for test '{}'" (head _desc))))) + (format " for test '{}'" (head _desc))))) (_suite.inc_failed) @@ -147,11 +147,11 @@ (let _indent (if (> _indent_case_len 0) - (string:format (+ "{: <" (toString _indent_case_len) "}") "") + (format (+ "{: <" (toString _indent_case_len) "}") "") "")) # Add the error message - (_suite.register_failure (string:format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_test_desc _desc))) + (_suite.register_failure (format "{}expected '{}' but got '{}'{}" _indent _lhs_repr _rhs_repr (_test_desc _desc))) (let _rhs_start (+ (len _lhs_repr) (len "expected ''"))) (let _lhs_align (len _lhs_repr)) @@ -161,7 +161,7 @@ (if _show_real (_suite.register_failure - (string:format + (format (+ "{}{: <" (toString (len "expected ")) "}" "{: <" (toString _rhs_start) "}{:~<" (toString _rhs_align) "} {}") _indent # to position one char before the first ' surrounding the expected value @@ -179,7 +179,7 @@ "")))) (if _show_expected - (_suite.register_failure (string:format (+ "{}{: <" (toString (len "expected ")) "}\\ {}") _indent "" _lhs))) })) + (_suite.register_failure (format (+ "{}{: <" (toString (len "expected ")) "}\\ {}") _indent "" _lhs))) })) # internal, do not use # This can only be used within a (nested or not) call to test:suite diff --git a/os.ark b/os.ark index 746a474..38852e9 100644 --- a/os.ark +++ b/os.ark @@ -1,11 +1,13 @@ +(import std.Sys :exec :platform) + # @brief Returns the home dir of the current user # @author https://github.com/Wafelack, https://github.com/SuperFola (let home_dir (fun () - (if (or (= sys:platform "Linux") (= sys:platform "Mac OSX") (= sys:platform "Unix")) + (if (or (= platform "Linux") (= platform "Mac OSX") (= platform "Unix")) { - (let username (sys:exec "whoami")) + (let username (exec "whoami")) (if (= username "root\n") "/root/" (+ "/home/" username)) } - (if (= sys:platform "Windows") (sys:exec "echo|set /p=%userprofile%"))))) + (if (= platform "Windows") (exec "echo|set /p=%userprofile%"))))) diff --git a/tests/all.ark b/tests/all.ark index 8d42d45..75332b3 100644 --- a/tests/all.ark +++ b/tests/all.ark @@ -1,6 +1,7 @@ (import events-tests) (import exceptions-tests) (import functional-tests) +(import io-tests) (import lazy-tests) (import list-tests) (import macros-tests) @@ -8,6 +9,7 @@ (import range-tests) (import string-tests) (import switch-tests) +(import sys-tests) (import std.List) @@ -15,14 +17,16 @@ events-tests:events-output exceptions-tests:exceptions-output functional-tests:functional-output + io-tests:io-output lazy-tests:lazy-output list-tests:list-output macros-tests:macros-output math-tests:math-output range-tests:range-output string-tests:string-output - switch-tests:switch-output ])) + switch-tests:switch-output + sys-tests:sys-output ])) (let success_count (list:sum (@ outputs 0))) (let failure_count (list:sum (@ outputs 1))) -(print (string:format "{:=<20}\nSuccesses: {} - Failures: {}\n" "=" success_count failure_count)) \ No newline at end of file +(print (format "{:=<20}\nSuccesses: {} - Failures: {}\n" "=" success_count failure_count)) \ No newline at end of file diff --git a/tests/io-tests.ark b/tests/io-tests.ark new file mode 100644 index 0000000..2d034a6 --- /dev/null +++ b/tests/io-tests.ark @@ -0,0 +1,39 @@ +(import std.IO) +(import std.Testing) + +(test:suite io { + (test:case "builtin__ files" { + (test:expect (not (builtin__io:fileExists? "test.txt"))) + (builtin__io:writeFile "test.txt" "hello, world!") + (test:expect (builtin__io:fileExists? "test.txt")) + (test:eq (builtin__io:readFile "test.txt") "hello, world!") + (builtin__io:appendToFile "test.txt" "bis") + (test:eq (builtin__io:readFile "test.txt") "hello, world!bis") + (test:expect (> (len (builtin__io:listFiles "./")) 0)) + (test:expect (not (builtin__io:dir? "test.txt"))) + (test:expect (not (builtin__io:fileExists? "temp"))) + (builtin__io:makeDir "temp") + (test:expect (builtin__io:fileExists? "temp")) + (test:expect (builtin__io:dir? "temp")) }) + + # clean up + (builtin__io:removeFile "test.txt") + (builtin__io:removeFile "temp/") + + (test:case "files" { + (test:expect (not (io:fileExists? "test.txt"))) + (io:writeFile "test.txt" "hello, world!") + (test:expect (io:fileExists? "test.txt")) + (test:eq (io:readFile "test.txt") "hello, world!") + (io:appendToFile "test.txt" "bis") + (test:eq (io:readFile "test.txt") "hello, world!bis") + (test:expect (> (len (io:listFiles "./")) 0)) + (test:expect (not (io:dir? "test.txt"))) + (test:expect (not (io:fileExists? "temp"))) + (io:makeDir "temp") + (test:expect (io:fileExists? "temp")) + (test:expect (io:dir? "temp")) }) + + # clean up + (io:removeFile "test.txt") + (io:removeFile "temp/") }) diff --git a/tests/lazy-tests.ark b/tests/lazy-tests.ark index 361addd..9d89724 100644 --- a/tests/lazy-tests.ark +++ b/tests/lazy-tests.ark @@ -1,5 +1,6 @@ (import std.Lazy) (import std.Testing) +(import std.Sys) (let calculate_the_sun_weight (fun () (begin (sys:sleep 50) 42))) (let memo (lazy:eval calculate_the_sun_weight)) diff --git a/tests/list-tests.ark b/tests/list-tests.ark index 824faf9..978bd50 100644 --- a/tests/list-tests.ark +++ b/tests/list-tests.ark @@ -7,6 +7,21 @@ (let zipped [[1 5] [2 6] [3 7] [4 8]]) (test:suite list { + (test:eq (builtin__list:reverse a) (list:reverse a)) + (test:eq (builtin__list:reverse []) (list:reverse [])) + + (test:eq (builtin__list:find a 0) (list:find a 0)) + (test:eq (builtin__list:find a 1) (list:find a 1)) + + (test:eq (builtin__list:slice a 1 2 1) (list:slice a 1 2 1)) + + (test:eq (builtin__list:sort [9 8 1]) (list:sort [9 8 1])) + (test:eq (builtin__list:sort []) (list:sort [])) + + (test:eq (builtin__list:fill 5 nil) (list:fill 5 nil)) + + (test:eq (builtin__list:setAt a 0 5) (list:setAt a 0 5)) + (list:forEach a (fun (e) { # just assert we have something, basically it's just a while + @ (test:neq e nil)})) diff --git a/tests/math-tests.ark b/tests/math-tests.ark index adce7dc..0087a49 100644 --- a/tests/math-tests.ark +++ b/tests/math-tests.ark @@ -2,6 +2,32 @@ (import std.Testing) (test:suite math { + (test:eq (builtin__math:exp 5) (math:exp 5)) + (test:eq (builtin__math:ln 5) (math:ln 5)) + (test:eq (builtin__math:ceil 5) (math:ceil 5)) + (test:eq (builtin__math:floor 5) (math:floor 5)) + (test:eq (builtin__math:round 5) (math:round 5)) + (test:eq (builtin__math:NaN? 5) (math:NaN? 5)) + (test:eq (builtin__math:Inf? 5) (math:Inf? 5)) + (test:eq builtin__math:pi math:pi) + (test:eq builtin__math:e math:e) + (test:eq builtin__math:tau math:tau) + (test:eq builtin__math:Inf math:Inf) + (test:expect (math:NaN? builtin__math:NaN)) + (test:expect (builtin__math:NaN? math:NaN)) + (test:eq (builtin__math:cos 5) (math:cos 5)) + (test:eq (builtin__math:sin 5) (math:sin 5)) + (test:eq (builtin__math:tan 5) (math:tan 5)) + (test:eq (builtin__math:arccos 0.5) (math:arccos 0.5)) + (test:eq (builtin__math:arcsin 0.5) (math:arcsin 0.5)) + (test:eq (builtin__math:arctan 0.5) (math:arctan 0.5)) + (test:eq (builtin__math:cosh 5) (math:cosh 5)) + (test:eq (builtin__math:sinh 5) (math:sinh 5)) + (test:eq (builtin__math:tanh 5) (math:tanh 5)) + (test:eq (builtin__math:acosh 5) (math:acosh 5)) + (test:eq (builtin__math:asinh 5) (math:asinh 5)) + (test:eq (builtin__math:atanh 0.5) (math:atanh 0.5)) + (test:eq (math:abs -1) 1) (test:eq (math:abs 1) 1) (test:expect (math:even 2)) @@ -17,9 +43,8 @@ (test:eq (math:pow 2 2) 4) (test:eq (math:pow 4 0.5) 2) - # small trick with toNumber because we have number's approximation because of the underlying double - (test:eq (math:fibo 31) (toNumber "1346269")) - (test:eq (math:fibo 32) (toNumber "2178309")) + (test:eq (math:fibo 31) 1346269) + (test:eq (math:fibo 32) 2178309) (test:eq (math:divs 6) [1 2 3 6]) (test:eq (math:divs 2) [1 2]) diff --git a/tests/string-tests.ark b/tests/string-tests.ark index a8088f9..11f48f4 100644 --- a/tests/string-tests.ark +++ b/tests/string-tests.ark @@ -2,6 +2,16 @@ (import std.Testing) (test:suite string { + (test:eq (builtin__string:find "abcd" "a") (string:find "abcd" "a")) + (test:eq (builtin__string:find "abcd" "e") (string:find "abcd" "e")) + (test:eq (builtin__string:find "aaacd" "a" 1) (string:findAfter "aaacd" "a" 1)) + + (test:eq (builtin__string:removeAt "abcd" 1) (string:removeAt "abcd" 1)) + (test:eq (builtin__string:setAt "abcd" 1 "z") (string:setAt "abcd" 1 "z")) + + (test:eq (builtin__string:ord "a") (string:ord "a")) + (test:eq (builtin__string:chr 65) (string:chr 65)) + (test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) (test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "abcdefghijklmnopqrstuvwxyz")) (test:eq "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (string:toUpper "abcdefghijklmnopqrstuvwxyz")) diff --git a/tests/sys-tests.ark b/tests/sys-tests.ark new file mode 100644 index 0000000..7db29a3 --- /dev/null +++ b/tests/sys-tests.ark @@ -0,0 +1,9 @@ +(import std.Sys) +(import std.Testing) + +(test:suite sys { + (test:eq builtin__sys:platform sys:platform) + (test:expect (!= "" sys:platform)) + + (test:eq builtin__sys:args sys:args) + (test:eq (type sys:args) "List") })