Skip to content

Commit

Permalink
Merge pull request #1638 from RickBarretto/update-tests
Browse files Browse the repository at this point in the history
adding/migrating some tests using `unitt`
  • Loading branch information
drkameleon authored May 22, 2024
2 parents 72879cf + d715f9a commit 1d1c4ed
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 251 deletions.
161 changes: 161 additions & 0 deletions tests/unitt/lib/collections/contains-.test.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import {unitt}!


suite "contains? for :string types" [

test ":string may contain :string" [
assert -> contains? "Arturo" "Art"
assert -> not? contains? "Arturo" "Ops!"
]

test ":string may contain :char" [
assert -> contains? "Arturo" 'A'
assert -> contains? "Arturo" 't'
assert -> not? contains? "Arturo" 'i'
]

test ":string may contain :literal" [
assert -> contains? "Arturo" 'Art
assert -> contains? "Arturo" 't
assert -> not? contains? "Arturo" 'i
]

test ":string may contain :regex" [
assert -> contains? "Arturo" {/[Art]/}
assert -> not? contains? "Arturo" {/[i]/}
]

]

suite "contains? for :range types" [

test ":range may contain :integer" [
assert -> contains? 1..10 1
assert -> contains? 1..10 5
assert -> contains? 1..10 7
assert -> contains? 1..10 10
assert -> not? contains? 1..10 0
]

test ":range may contain :floating" [
assert -> contains? 1..10 1.0
assert -> contains? 1..10 5.0
assert -> contains? 1..10 7.0
assert -> contains? 1..10 10.0
assert -> not? contains? 1..10 0.0
]

test ":range is a discrete interval" [
assert -> not? contains? 1..10 5.5
assert -> not? contains? (range.step: 2 1 10) 2
]

]

suite "contains? for :block types" [

test ":block may contain :any" [
sample: @[1 "Example" 'example [] #[]]

assert -> contains? sample 1
assert -> contains? sample "Example"
assert -> contains? sample 'example
assert -> contains? sample []
assert -> contains? sample #[]
assert -> not? contains? sample "Hmm"
]

test "contains?.deep can find it into nested :blocks" [
assert -> contains?.deep [1 2 3 [4 5] 6 7] 3
assert -> contains?.deep [1 2 3 [4 5] 6 7] 4
assert -> contains?.deep [1 2 3 [4 5] 6 7] 5
assert -> contains?.deep [1 2 3 [4 5] 6 7] [4 5]

assert -> contains? [1 2 3 [4 5] 6 7] [4 5]
assert -> not? contains? [1 2 3 [4 5] 6 7] 4
assert -> not? contains? [1 2 3 [4 5] 6 7] 5
]

test "contains?.deep can't find :dictionary's values into nested :blocks" [
assert -> not? contains?.deep @[#[name: "Joe"]] "Joe"
]

]

suite "contains? for :dictionary types" [

sample: #[
name: "John"
surname: "Doe"
age: 22
role: 'programmer
favoriteLanguages: [
Arturo Python Ruby Ada Rust Zig Nim
]
parents: #[
father: "Joe"
mother: "Jane"
]
]

test ":dictionary may contain :any" [

assert -> contains? sample "John"
assert -> contains? sample "Doe"
assert -> contains? sample 'programmer
assert -> contains? sample 22
assert -> contains? sample [Arturo Python Ruby Ada Rust Zig Nim]
assert -> not? contains? sample "Joe"
assert -> not? contains? sample "Jane"
]

test "contains?.deep can find it into nested :dictionary" [
assert -> contains?.deep sample "Joe"
assert -> contains?.deep sample "Jane"
]

test "contains?.deep can't find :block's values into nested :dictionary" [
assert -> not? contains?.deep sample (to :word "Arturo")
]

]

suite "test .at attribute" [

str: "Arturo"
blk: [1 2 3 4 5 6]
dict: #[name: "Joe" surname: "Doe"]

test.prop "element at 0 must be equal to first" [
assert -> contains?.at: 0 str first str
assert -> contains?.at: 0 blk first blk
assert -> contains?.at: 0 dict "Joe"
]

test.prop "element at high must be equal to last" [
assert -> contains?.at: (dec size str) str (last str)
assert -> contains?.at: (dec size blk) blk (last blk)
assert -> contains?.at: 1 dict "Doe"
]

test.prop "element at x must be equal to get x" [
do.times: 5 [
index: (random 0 100) % (dec size str)
assert -> contains?.at: index str (str\[index])

index: (random 0 100) % (dec size blk)
assert -> contains?.at: index blk (blk\[index])
]
]

test.skip "negative index should verify from backyards" [
assert -> contains?.at: neg 1 str (last str)
assert -> contains?.at: neg 1 blk (last blk)
assert -> contains?.at: neg 1 dict (last dict)
]

test.skip "should throw for index out of bounds" [
assert -> throws? [contains?.at: 2 [0 1] 0]
]

]
57 changes: 57 additions & 0 deletions tests/unitt/lib/core/new.test.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {unitt}!

pairs: #[
integer: [2 3]
string: ["John" "Doe"]
block: [[1 2 3] [4 5 6]]
dictionary: @[
#[name: "Joe" surname: "Doe"]
#[name: "Jane" surname: "Zurich"]
]
]

suite "test if new object reference does not change the older one" [

test "change new primitive values does not change the old ones" [
loop (values new pairs) [sample][
a: sample\0
b: new a
b: sample\1

assert -> a <> b
]
]

test "change the new block's value does not change the old one" [
a: [1 2 3 4 5]
b: new a
b\2: 8

assert -> a <> b
]

test "change the new block's value does not change the old one" [
a: #[name: "John" surname: "Doe"]
b: new a
b\name: "Jane"

assert -> a <> b
]

]

suite "test if new allocate the object to a new address" [

test "change new primitive values does not change the old ones" [
loop (values new pairs) [sample][
a: sample\0
b: new a

addressOfA: (info.get 'a | get "address")
addressOfB: (info.get 'b | get "address")

assert -> addressOfA <> addressOfB
]
]

]
65 changes: 0 additions & 65 deletions tests/unittests/deepcopies.art

This file was deleted.

17 changes: 0 additions & 17 deletions tests/unittests/deepcopies.res

This file was deleted.

Loading

0 comments on commit 1d1c4ed

Please sign in to comment.