2022-08-16 20:23:48 +03:00
|
|
|
module datatypes
|
|
|
|
|
|
|
|
fn test_exists() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add('foo')
|
|
|
|
assert set.exists('foo')
|
|
|
|
assert set.exists('bar') == false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_remove() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.remove('foo')
|
|
|
|
set.add('foo')
|
|
|
|
assert set.exists('foo')
|
|
|
|
set.remove('foo')
|
|
|
|
assert set.exists('foo') == false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_size() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add('foo')
|
|
|
|
set.add('foo')
|
|
|
|
assert set.size() == 1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_pop() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add('foo')
|
|
|
|
set.pop() or { return }
|
|
|
|
assert set.exists('foo') == false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_clear() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add('foo')
|
|
|
|
set.clear()
|
|
|
|
assert set.size() == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_rest() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add('foo')
|
|
|
|
set.add('bar')
|
|
|
|
array := set.rest() or { return }
|
|
|
|
assert array.len == 1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_equal() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut first_set := Set[string]{}
|
|
|
|
mut second_set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
first_set.add('foo')
|
2022-08-26 07:03:23 +03:00
|
|
|
assert second_set != first_set
|
2022-08-16 20:23:48 +03:00
|
|
|
second_set.add('foo')
|
2022-08-26 07:03:23 +03:00
|
|
|
assert second_set == first_set
|
2022-08-16 20:23:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_is_empty() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
assert set.is_empty()
|
|
|
|
set.add('foo')
|
|
|
|
assert set.is_empty() == false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_union() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut first_set := Set[string]{}
|
|
|
|
mut second_set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
first_set.add_all(['b', 'c', 'd'])
|
|
|
|
second_set.add_all(['a', 'e'])
|
|
|
|
mut third_set := first_set.@union(second_set)
|
|
|
|
assert third_set.exists('a')
|
|
|
|
assert third_set.exists('b')
|
|
|
|
assert third_set.exists('c')
|
|
|
|
assert third_set.exists('d')
|
|
|
|
assert third_set.exists('e')
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_intersection() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut first_set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
first_set.add_all(['foo', 'bar', 'baz'])
|
2022-11-26 19:23:26 +03:00
|
|
|
mut second_set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
second_set.add_all(['bar', 'baz', 'boo'])
|
|
|
|
mut third_set := first_set.intersection(second_set)
|
|
|
|
assert third_set.exists('foo') == false
|
|
|
|
assert third_set.exists('bar')
|
|
|
|
assert third_set.exists('baz')
|
|
|
|
assert third_set.exists('boo') == false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_difference() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut first_set := Set[string]{}
|
|
|
|
mut second_set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
first_set.add_all(['foo', 'bar', 'baz'])
|
|
|
|
second_set.add_all(['bar', 'baz', 'boo'])
|
2022-08-26 07:03:23 +03:00
|
|
|
mut third_set := first_set - second_set
|
2022-08-16 20:23:48 +03:00
|
|
|
assert third_set.exists('foo')
|
|
|
|
assert third_set.exists('bar') == false
|
|
|
|
assert third_set.exists('baz') == false
|
|
|
|
assert third_set.exists('boo') == false
|
|
|
|
first_set.clear()
|
|
|
|
second_set.clear()
|
|
|
|
third_set.clear()
|
|
|
|
first_set.add_all(['bar', 'baz', 'boo'])
|
|
|
|
second_set.add_all(['foo', 'bar', 'baz'])
|
2022-08-26 07:03:23 +03:00
|
|
|
third_set = first_set - second_set
|
2022-08-16 20:23:48 +03:00
|
|
|
assert third_set.exists('foo') == false
|
|
|
|
assert third_set.exists('bar') == false
|
|
|
|
assert third_set.exists('baz') == false
|
|
|
|
assert third_set.exists('boo')
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_subset() {
|
2022-11-26 19:23:26 +03:00
|
|
|
mut set := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
set.add_all(['a', 'b', 'c'])
|
2022-11-26 19:23:26 +03:00
|
|
|
mut subset := Set[string]{}
|
2022-08-16 20:23:48 +03:00
|
|
|
subset.add_all(['b', 'c'])
|
|
|
|
assert set.subset(subset)
|
|
|
|
}
|