Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Dict.ark
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@
# @author https://github.com/SuperFola
(let add (fun (_D _key _value) (builtin__dict:add _D _key _value)))

# @brief Checks if the dictionary has a given key
# @param _D dictionary
# =begin
# (let data (dict "key" "value"))
# (print (dict:contains? data "key")) # true
# (print (dict:contains? data "test")) # false
# =end
# @author https://github.com/SuperFola
(let contains? (fun (_D _key) (builtin__dict:contains _D _key)))

# @brief Checks if the dictionary has a given key
# @details **Deprecated, use `contains?`**
# @param _D dictionary
# =begin
# (let data (dict "key" "value"))
# (print (dict:contains data "key")) # true
# (print (dict:contains data "test")) # false
# =end
# @author https://github.com/SuperFola
(let contains contains?)

# @brief Get a value from a given dictionary using a key, or a default value if it doesn't exist
# @param _D dictionary
# @param _key key to get
Expand Down Expand Up @@ -53,16 +74,6 @@
(add _D _key (_f (get _D _key)))
(add _D _key _default))))

# @brief Checks if the dictionary has a given key
# @param _D dictionary
# =begin
# (let data (dict "key" "value"))
# (print (dict:contains data "key")) # true
# (print (dict:contains data "test")) # false
# =end
# @author https://github.com/SuperFola
(let contains (fun (_D _key) (builtin__dict:contains _D _key)))

# @brief Deletes an entry from a dictionary, given a key
# @details The dictionary is modified in place
# @param _D dictionary
Expand Down
2 changes: 1 addition & 1 deletion List.ark
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
# @details The original list is not modified.
# =begin
# (import std.Math)
# (print (list:filter [1 2 3 4 5 6 7 8 9] math:even)) # [2 4 6 8]
# (print (list:filter [1 2 3 4 5 6 7 8 9] math:even?)) # [2 4 6 8]
# =end
# @author https://github.com/rstefanic
(let filter (fun (_L _f) {
Expand Down
16 changes: 14 additions & 2 deletions Math.ark
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,24 @@
# @brief Return true if the number is even, false otherwise
# @param _n the number
# @author https://github.com/rstefanic
(let even (fun (_n) (= 0 (mod _n 2))))
(let even? (fun (_n) (= 0 (mod _n 2))))

# @brief Return true if the number is even, false otherwise
# @details **Deprecated, use `even?`**
# @param _n the number
# @author https://github.com/rstefanic
(let even even?)

# @brief Return true if the number is odd, false otherwise
# @param _n the number
# @author https://github.com/rstefanic
(let odd? (fun (_n) (= 1 (abs (mod _n 2)))))

# @brief Return true if the number is odd, false otherwise
# @details **Deprecated, use `odd?`**
# @param _n the number
# @author https://github.com/rstefanic
(let odd (fun (_n) (= 1 (abs (mod _n 2)))))
(let odd odd?)

# @brief Get the minimum between two numbers
# @param _a the first number
Expand Down
2 changes: 1 addition & 1 deletion Range.ark
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# =begin
# (import std.Math)
# (let obj (range:range 1 10))
# (print (range:filter obj math:even)) # [2 4 6 8]
# (print (range:filter obj math:even?)) # [2 4 6 8]
# =end
# @author https://github.com/SuperFola
(let filter (fun (_range _fun) {
Expand Down
27 changes: 26 additions & 1 deletion String.ark
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@
# @author https://github.com/SuperFola
(let setAt (fun (_str _index _x) (builtin__string:setAt _str _index _x)))

# @brief Check if a string contains a word
# @param _str String where the lookup occurs
# @param _word Word to look up for
# @author https://github.com/SuperFola
(let contains? (fun (_str _word)
(!= -1 (find _str _word))))

# @brief Check if a string contains a word for a set of words
# @param _str String where the lookup occurs
# @param _set_of_words Words to look for
# =begin
# (let words ["hello" "world"])
# (print (containsAnyOf "Hello, world! I like almonds" words)) # true
# (print (containsAnyOf "Hello, world!" string:punctuation)) # true
# =end
# @author https://github.com/SuperFola
(let containsAnyOf? (fun (_str _set_of_words) {
(mut _contains false)
(mut _i 0)
(while (and (not _contains) (< _i (len _set_of_words))) {
(if (!= -1 (find _str (@ _set_of_words _i)))
(set _contains true))
(set _i (+ 1 _i)) })
_contains }))

# @brief Check if a string is empty or only consists of whitespaces
# @param _str the string to check
# =begin
Expand Down Expand Up @@ -254,7 +279,7 @@
# @details Returns a list of strings. Example :
# =begin
# (let message "hello world, I like boats")
# (let splitted (string:split message " "))
# (let as-list (string:split message " "))
# =end
# @author https://github.com/Natendrtfm
(let split (fun (_string _separator) {
Expand Down
8 changes: 4 additions & 4 deletions Testing.ark
Original file line number Diff line number Diff line change
Expand Up @@ -203,30 +203,30 @@
(testing:_report_success)) })

# @brief Compare two values that should be equal and generate a test case
# @param _expected expected value
# @param _expr computed value to test
# @param _expected expected value
# @param _desc an optional description (string) for the test
# =begin
# (test:suite name {
# (test:eq 6 (my_function 1 2 3))
# (test:eq 5 (foo) "foo should return 5")})
# =end
# @author https://github.com/SuperFola
(macro test:eq (_expected _expr ..._desc) {
(macro test:eq (_expr _expected ..._desc) {
(if (= ($as-is _expected) ($as-is _expr))
(testing:_report_success)
(testing:_report_error ($as-is _expected) ($as-is _expr) ($repr _expected) ($repr _expr) _desc)) })

# @brief Compare two values that should **not** be equal and generate a test case
# @param _unexpected the value we don't want
# @param _value tested value
# @param _unexpected the value we don't want
# @param _desc an optional description (string) for the test
# =begin
# (test:suite name {
# (test:neq 0 (my_function 1 2 3))})
# =end
# @author https://github.com/SuperFola
(macro test:neq (_unexpected _value ..._desc) {
(macro test:neq (_value _unexpected ..._desc) {
(if (!= ($as-is _unexpected) ($as-is _value))
(testing:_report_success)
(testing:_report_error ($as-is _unexpected) ($as-is _value) ($repr _unexpected) ($repr _value) _desc)) })
Expand Down
24 changes: 12 additions & 12 deletions tests/dict-tests.ark
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
(test:eq (dict:getOrElse empty "key" 0) 0) })

(test:case "contains" {
(test:expect (dict:contains d "key"))
(test:expect (dict:contains d 5))
(test:expect (dict:contains d true))
(test:expect (dict:contains d false))
(test:expect (dict:contains d foo))
(test:expect (dict:contains d closure))
(test:expect (not (dict:contains d -1)))
(test:expect (not (dict:contains d "hello")))
(test:expect (not (dict:contains d d))) })
(test:expect (dict:contains? d "key"))
(test:expect (dict:contains? d 5))
(test:expect (dict:contains? d true))
(test:expect (dict:contains? d false))
(test:expect (dict:contains? d foo))
(test:expect (dict:contains? d closure))
(test:expect (not (dict:contains? d -1)))
(test:expect (not (dict:contains? d "hello")))
(test:expect (not (dict:contains? d d))) })

(test:case "size" {
(test:eq (dict:size d) 6)
Expand Down Expand Up @@ -153,9 +153,9 @@
(test:case "filter!" {
(dict:filter! d2 filter_odd)
(test:eq (dict:size d2) 2)
(test:expect (dict:contains d2 "a"))
(test:expect (not (dict:contains d2 "b")))
(test:expect (dict:contains d2 "c"))
(test:expect (dict:contains? d2 "a"))
(test:expect (not (dict:contains? d2 "b")))
(test:expect (dict:contains? d2 "c"))
(test:eq (dict:get d2 "a") 1)
(test:eq (dict:get d2 "c") 3)

Expand Down
4 changes: 2 additions & 2 deletions tests/list-tests.ark
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(import std.List)
(import std.Math :even)
(import std.Math :even?)
(import std.Testing)

(let a [1 2 3])
Expand Down Expand Up @@ -69,7 +69,7 @@
(test:eq (list:dropWhile a (fun (c) (< c 5))) []) })

(test:case "filter" {
(test:eq (list:filter a math:even) [2])
(test:eq (list:filter a math:even?) [2])
(test:eq (list:filter a (fun (e) (> e 100))) [])
(test:eq (list:filter [] (fun (e) (> e 100))) []) })

Expand Down
8 changes: 4 additions & 4 deletions tests/math-tests.ark
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

(test:eq (math:abs -1) 1)
(test:eq (math:abs 1) 1)
(test:expect (math:even 2))
(test:expect (math:even -2))
(test:expect (math:odd 1))
(test:expect (math:odd -1))
(test:expect (math:even? 2))
(test:expect (math:even? -2))
(test:expect (math:odd? 1))
(test:expect (math:odd? -1))
(test:eq (math:min 1 2) 1)
(test:eq (math:min 1 -2) -2)
(test:eq (math:min 0.5 0.2) 0.2)
Expand Down
4 changes: 2 additions & 2 deletions tests/range-tests.ark
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(import std.Range:*)
(import std.Math :even)
(import std.Math :even?)
(import std.Testing)

(test:suite range {
Expand All @@ -17,7 +17,7 @@
(range:forEach r (fun (e)
(test:neq e nil)))

(let filtered (range:filter r math:even))
(let filtered (range:filter r math:even?))
(test:eq filtered [0 2 4 6 8])

(let mapped (range:map r (fun (e) (* e e))))
Expand Down
11 changes: 11 additions & 0 deletions tests/string-tests.ark
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
(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:expect (string:contains? "hello, world" "h"))
(test:expect (string:contains? "hello, world" "hello"))
(test:expect (string:contains? "hello, world" "world"))
(test:expect (string:contains? "hello, world" ","))
(test:expect (not (string:contains? "hello, world" "!")))

(test:expect (string:containsAnyOf? "Hello, world" ["world" "one"]))
(test:expect (string:containsAnyOf? "Hello, world" string:punctuation))
(test:expect (not (string:containsAnyOf? "Hello, world" [])))
(test:expect (not (string:containsAnyOf? "Hello, world" ["nice" "cool"])))

(test:eq (string:emptyOrWhitespace? "") true)
(test:eq (string:emptyOrWhitespace? " ") true)
(test:eq (string:emptyOrWhitespace? " ") true)
Expand Down
Loading