slovo/examples/projects/std-layout-local-vec_i64/src/main.slo

395 lines
15 KiB
Plaintext

(module main)
(import vec_i64 (empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of sum concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range))
(fn imported_empty_length () -> i32
(len (empty)))
(fn imported_pair_index () -> i64
(at (pair 40i64 41i64) 1))
(fn original_len_after_append () -> i32
(let values (vec i64) (empty))
(let more (vec i64) (append values 9i64))
(len values))
(fn option_i64_is_some_value ((value (option i64)) (expected i64)) -> bool
(if (is_some value)
(= (unwrap_some value) expected)
false))
(fn option_i32_is_some_value ((value (option i32)) (expected i32)) -> bool
(if (is_some value)
(= (unwrap_some value) expected)
false))
(fn imported_builder_helpers_ok () -> bool
(if (= (len (singleton 42i64)) 1)
(if (= (len (append2 (empty) 10i64 20i64)) 2)
(if (= (len (append3 (singleton 10i64) 20i64 30i64 40i64)) 4)
(if (= (pair 5i64 6i64) (append2 (empty) 5i64 6i64))
(= (triple 7i64 8i64 9i64) (append3 (empty) 7i64 8i64 9i64))
false)
false)
false)
false))
(fn imported_query_helpers_ok () -> bool
(if (is_empty (empty))
(if (= (first_or (empty) 9i64) 9i64)
(if (= (first_or (pair 40i64 41i64) 9i64) 40i64)
(if (= (last_or (triple 10i64 20i64 30i64) 9i64) 30i64)
(if (= (index_or (pair 40i64 41i64) -1 7i64) 7i64)
(if (= (index_or (pair 40i64 41i64) 9 7i64) 7i64)
(= (index_or (pair 40i64 41i64) 1 7i64) 41i64)
false)
false)
false)
false)
false)
false))
(fn imported_option_query_helpers_ok () -> bool
(if (is_none (first_option (empty)))
(if (option_i64_is_some_value (first_option (pair 40i64 41i64)) 40i64)
(if (is_none (last_option (empty)))
(if (option_i64_is_some_value (last_option (triple 10i64 20i64 30i64)) 30i64)
(if (is_none (index_option (pair 40i64 41i64) -1))
(if (is_none (index_option (pair 40i64 41i64) 9))
(if (option_i64_is_some_value (index_option (pair 40i64 41i64) 1) 41i64)
(if (is_none (index_of_option (append3 (pair 10i64 20i64) 30i64 20i64 10i64) 99i64))
(if (option_i32_is_some_value (index_of_option (append3 (pair 10i64 20i64) 30i64 20i64 10i64) 20i64) 1)
(if (is_none (last_index_of_option (append3 (pair 10i64 20i64) 30i64 20i64 10i64) 99i64))
(option_i32_is_some_value (last_index_of_option (append3 (pair 10i64 20i64) 30i64 20i64 10i64) 20i64) 3)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false))
(fn imported_count_of_helper_ok () -> bool
(let values (vec i64) (append3 (pair 10i64 20i64) 30i64 20i64 10i64))
(if (= (count_of (empty) 20i64) 0)
(if (= (count_of values 99i64) 0)
(if (= (count_of values 20i64) 2)
(= (count_of values 10i64) 2)
false)
false)
false))
(fn imported_starts_with_helper_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let prefix (vec i64) (pair 10i64 20i64))
(let longer_prefix (vec i64) (append2 values 60i64 70i64))
(let mismatched_prefix (vec i64) (pair 20i64 30i64))
(if (starts_with values (empty))
(if (starts_with values prefix)
(if (starts_with values values)
(if (starts_with values longer_prefix)
false
(if (starts_with values mismatched_prefix)
false
(if (= values (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(= prefix (pair 10i64 20i64))
false)))
false)
false)
false))
(fn imported_ends_with_helper_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let suffix (vec i64) (pair 40i64 50i64))
(let longer_suffix (vec i64) (append2 values 60i64 70i64))
(let mismatched_suffix (vec i64) (pair 40i64 51i64))
(if (ends_with values (empty))
(if (ends_with values suffix)
(if (ends_with values values)
(if (ends_with values longer_suffix)
false
(if (ends_with values mismatched_suffix)
false
(if (= values (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(= suffix (pair 40i64 50i64))
false)))
false)
false)
false))
(fn imported_without_suffix_helper_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let suffix (vec i64) (pair 40i64 50i64))
(let longer_suffix (vec i64) (append2 values 60i64 70i64))
(let mismatched_suffix (vec i64) (pair 40i64 51i64))
(if (= (without_suffix values (empty)) values)
(if (= (without_suffix values values) (empty))
(if (= (without_suffix values suffix) (triple 10i64 20i64 30i64))
(if (= (without_suffix values longer_suffix) values)
(if (= (without_suffix values mismatched_suffix) values)
(if (= values (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(= suffix (pair 40i64 50i64))
false)
false)
false)
false)
false)
false))
(fn imported_without_prefix_helper_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let prefix (vec i64) (pair 10i64 20i64))
(let longer_prefix (vec i64) (append2 values 60i64 70i64))
(let mismatched_prefix (vec i64) (pair 10i64 21i64))
(if (= (without_prefix values (empty)) values)
(if (= (without_prefix values values) (empty))
(if (= (without_prefix values prefix) (triple 30i64 40i64 50i64))
(if (= (without_prefix values longer_prefix) values)
(if (= (without_prefix values mismatched_prefix) values)
(if (= values (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(= prefix (pair 10i64 20i64))
false)
false)
false)
false)
false)
false))
(fn imported_transform_helpers_ok () -> bool
(if (= (concat (empty) (pair 7i64 8i64)) (pair 7i64 8i64))
(if (= (concat (pair 1i64 2i64) (triple 3i64 4i64 5i64)) (append3 (pair 1i64 2i64) 3i64 4i64 5i64))
(if (= (take (triple 10i64 20i64 30i64) -4) (empty))
(if (= (take (triple 10i64 20i64 30i64) 2) (pair 10i64 20i64))
(if (= (take (pair 10i64 20i64) 9) (pair 10i64 20i64))
(if (= (drop (triple 10i64 20i64 30i64) -4) (triple 10i64 20i64 30i64))
(if (= (drop (triple 10i64 20i64 30i64) 2) (singleton 30i64))
(if (= (drop (pair 10i64 20i64) 9) (empty))
(if (= (reverse (empty)) (empty))
(= (reverse (append3 (pair 10i64 20i64) 30i64 40i64 50i64)) (append3 (pair 50i64 40i64) 30i64 20i64 10i64))
false)
false)
false)
false)
false)
false)
false)
false)
false))
(fn imported_subvec_helper_ok () -> bool
(let original (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(if (= (subvec original -1 2) (empty))
(if (= (subvec original 3 3) (empty))
(if (= (subvec original 9 10) (empty))
(if (= (subvec original 2 99) (triple 30i64 40i64 50i64))
(if (= (subvec original 1 4) (triple 20i64 30i64 40i64))
(= original (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
false)
false)
false)
false)
false))
(fn imported_insert_helper_ok () -> bool
(let values (vec i64) (triple 10i64 20i64 30i64))
(if (= (insert_at values 1 99i64) (append2 (pair 10i64 99i64) 20i64 30i64))
(if (= (insert_at values 3 99i64) (append values 99i64))
(if (= values (triple 10i64 20i64 30i64))
(if (= (insert_at values -1 99i64) values)
(= (insert_at values 4 99i64) values)
false)
false)
false)
false))
(fn imported_insert_range_helper_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let inserted (vec i64) (pair 77i64 88i64))
(if (= (insert_range values -1 inserted) values)
(if (= (insert_range values 2 inserted) (append3 (append2 (pair 10i64 20i64) 77i64 88i64) 30i64 40i64 50i64))
(if (= (insert_range values 5 inserted) (append2 (append2 (triple 10i64 20i64 30i64) 40i64 50i64) 77i64 88i64))
(if (= values (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(if (= inserted (pair 77i64 88i64))
(= (insert_range values 6 inserted) values)
false)
false)
false)
false)
false))
(fn imported_replace_helper_ok () -> bool
(if (= (replace_at (triple 10i64 20i64 30i64) 1 99i64) (triple 10i64 99i64 30i64))
(if (= (replace_at (triple 10i64 20i64 30i64) -1 99i64) (triple 10i64 20i64 30i64))
(= (replace_at (pair 10i64 20i64) 2 99i64) (pair 10i64 20i64))
false)
false))
(fn imported_replace_range_helper_ok () -> bool
(let original (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(let replacement (vec i64) (pair 77i64 88i64))
(if (= (replace_range original -1 2 replacement) original)
(if (= (replace_range original 3 3 replacement) original)
(if (= (replace_range original 4 2 replacement) original)
(if (= (replace_range original 5 9 replacement) original)
(if (= (replace_range original 2 99 replacement) (append2 (pair 10i64 20i64) 77i64 88i64))
(if (= (replace_range original 1 4 replacement) (append2 (pair 10i64 77i64) 88i64 50i64))
(if (= original (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(= replacement (pair 77i64 88i64))
false)
false)
false)
false)
false)
false)
false))
(fn imported_remove_helper_ok () -> bool
(let original (vec i64) (triple 10i64 20i64 30i64))
(let removed_middle (vec i64) (remove_at original 1))
(if (= removed_middle (pair 10i64 30i64))
(if (= (len removed_middle) 2)
(if (= (remove_at original 0) (pair 20i64 30i64))
(if (= (remove_at original 2) (pair 10i64 20i64))
(if (= original (triple 10i64 20i64 30i64))
(if (= (remove_at original -1) original)
(= (remove_at original 3) original)
false)
false)
false)
false)
false)
false))
(fn imported_remove_range_helper_ok () -> bool
(let original (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(if (= (remove_range original -1 2) original)
(if (= (remove_range original 3 3) original)
(if (= (remove_range original 4 2) original)
(if (= (remove_range original 5 9) original)
(if (= (remove_range original 2 99) (pair 10i64 20i64))
(if (= (remove_range original 1 4) (pair 10i64 50i64))
(= original (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
false)
false)
false)
false)
false)
false))
(fn imported_real_program_helpers_ok () -> bool
(let values (vec i64) (append2 (triple 10i64 20i64 30i64) 40i64 50i64))
(if (= (original_len_after_append) 0)
(if (contains values 20i64)
(if (contains values 99i64)
false
(= (sum values) 150i64))
false)
false))
(fn helpers_all_ok () -> bool
(if (= (imported_empty_length) 0)
(if (= (imported_pair_index) 41i64)
(if (imported_builder_helpers_ok)
(if (imported_query_helpers_ok)
(if (imported_option_query_helpers_ok)
(if (imported_count_of_helper_ok)
(if (imported_starts_with_helper_ok)
(if (imported_ends_with_helper_ok)
(if (imported_without_suffix_helper_ok)
(if (imported_without_prefix_helper_ok)
(if (imported_transform_helpers_ok)
(if (imported_subvec_helper_ok)
(if (imported_insert_helper_ok)
(if (imported_insert_range_helper_ok)
(if (imported_replace_helper_ok)
(if (imported_replace_range_helper_ok)
(if (imported_remove_helper_ok)
(if (imported_remove_range_helper_ok)
(imported_real_program_helpers_ok)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false))
(test "explicit local vec_i64 empty len facade"
(= (imported_empty_length) 0))
(test "explicit local vec_i64 direct at facade"
(= (imported_pair_index) 41i64))
(test "explicit local vec_i64 builder helpers"
(imported_builder_helpers_ok))
(test "explicit local vec_i64 query helpers"
(imported_query_helpers_ok))
(test "explicit local vec_i64 option query helpers"
(imported_option_query_helpers_ok))
(test "explicit local vec_i64 count_of helper"
(imported_count_of_helper_ok))
(test "explicit local vec_i64 starts_with helper"
(imported_starts_with_helper_ok))
(test "explicit local vec_i64 ends_with helper"
(imported_ends_with_helper_ok))
(test "explicit local vec_i64 without_suffix helper"
(imported_without_suffix_helper_ok))
(test "explicit local vec_i64 without_prefix helper"
(imported_without_prefix_helper_ok))
(test "explicit local vec_i64 transform helpers"
(imported_transform_helpers_ok))
(test "explicit local vec_i64 subvec helper"
(imported_subvec_helper_ok))
(test "explicit local vec_i64 insert helper"
(imported_insert_helper_ok))
(test "explicit local vec_i64 insert range helper"
(imported_insert_range_helper_ok))
(test "explicit local vec_i64 replace helper"
(imported_replace_helper_ok))
(test "explicit local vec_i64 replace range helper"
(imported_replace_range_helper_ok))
(test "explicit local vec_i64 remove helper"
(imported_remove_helper_ok))
(test "explicit local vec_i64 remove range helper"
(imported_remove_range_helper_ok))
(test "explicit local vec_i64 real program helpers"
(imported_real_program_helpers_ok))
(test "explicit local vec_i64 helpers all"
(helpers_all_ok))
(fn main () -> i32
(if (helpers_all_ok)
0
1))