slovo/docs/language/examples/projects/std-import-vec_f64/src/main.slo
2026-05-22 08:38:43 +02:00

380 lines
14 KiB
Plaintext

(module main)
(import std.vec_f64 (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 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 () -> f64
(at (pair 40.0 41.0) 1))
(fn original_len_after_append () -> i32
(let values (vec f64) (empty))
(let more (vec f64) (append values 9.0))
(len values))
(fn option_f64_is_some_value ((value (option f64)) (expected f64)) -> 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 42.0)) 1)
(if (= (len (append2 (empty) 10.0 20.0)) 2)
(if (= (len (append3 (singleton 10.0) 20.0 30.0 40.0)) 4)
(if (= (pair 5.0 6.0) (append2 (empty) 5.0 6.0))
(= (triple 7.0 8.0 9.0) (append3 (empty) 7.0 8.0 9.0))
false)
false)
false)
false))
(fn imported_query_helpers_ok () -> bool
(if (is_empty (empty))
(if (= (first_or (empty) 9.0) 9.0)
(if (= (first_or (pair 40.0 41.0) 9.0) 40.0)
(if (= (last_or (triple 10.0 20.0 30.0) 9.0) 30.0)
(if (= (index_or (pair 40.0 41.0) -1 7.0) 7.0)
(if (= (index_or (pair 40.0 41.0) 9 7.0) 7.0)
(= (index_or (pair 40.0 41.0) 1 7.0) 41.0)
false)
false)
false)
false)
false)
false))
(fn imported_option_query_helpers_ok () -> bool
(if (is_none (first_option (empty)))
(if (option_f64_is_some_value (first_option (pair 40.0 41.0)) 40.0)
(if (is_none (last_option (empty)))
(if (option_f64_is_some_value (last_option (triple 10.0 20.0 30.0)) 30.0)
(if (is_none (index_option (pair 40.0 41.0) -1))
(if (is_none (index_option (pair 40.0 41.0) 9))
(if (option_f64_is_some_value (index_option (pair 40.0 41.0) 1) 41.0)
(if (is_none (index_of_option (append3 (pair 10.0 20.0) 30.0 20.0 10.0) 99.0))
(if (option_i32_is_some_value (index_of_option (append3 (pair 10.0 20.0) 30.0 20.0 10.0) 20.0) 1)
(if (is_none (last_index_of_option (append3 (pair 10.0 20.0) 30.0 20.0 10.0) 99.0))
(option_i32_is_some_value (last_index_of_option (append3 (pair 10.0 20.0) 30.0 20.0 10.0) 20.0) 3)
false)
false)
false)
false)
false)
false)
false)
false)
false)
false))
(fn imported_starts_with_helper_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let prefix (vec f64) (pair 10.0 20.0))
(let longer_prefix (vec f64) (append2 values 60.0 70.0))
(let mismatched_prefix (vec f64) (pair 20.0 30.0))
(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 10.0 20.0 30.0) 40.0 50.0))
(= prefix (pair 10.0 20.0))
false)))
false)
false)
false))
(fn imported_ends_with_helper_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let suffix (vec f64) (pair 40.0 50.0))
(let longer_suffix (vec f64) (append2 values 60.0 70.0))
(let mismatched_suffix (vec f64) (pair 40.0 51.0))
(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 10.0 20.0 30.0) 40.0 50.0))
(= suffix (pair 40.0 50.0))
false)))
false)
false)
false))
(fn imported_without_suffix_helper_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let suffix (vec f64) (pair 40.0 50.0))
(let longer_suffix (vec f64) (append2 values 60.0 70.0))
(let mismatched_suffix (vec f64) (pair 40.0 51.0))
(if (= (without_suffix values (empty)) values)
(if (= (without_suffix values values) (empty))
(if (= (without_suffix values suffix) (triple 10.0 20.0 30.0))
(if (= (without_suffix values longer_suffix) values)
(if (= (without_suffix values mismatched_suffix) values)
(if (= values (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(= suffix (pair 40.0 50.0))
false)
false)
false)
false)
false)
false))
(fn imported_without_prefix_helper_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let prefix (vec f64) (pair 10.0 20.0))
(let longer_prefix (vec f64) (append2 values 60.0 70.0))
(let mismatched_prefix (vec f64) (pair 10.0 21.0))
(if (= (without_prefix values (empty)) values)
(if (= (without_prefix values values) (empty))
(if (= (without_prefix values prefix) (triple 30.0 40.0 50.0))
(if (= (without_prefix values longer_prefix) values)
(if (= (without_prefix values mismatched_prefix) values)
(if (= values (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(= prefix (pair 10.0 20.0))
false)
false)
false)
false)
false)
false))
(fn imported_transform_helpers_ok () -> bool
(if (= (concat (empty) (pair 7.0 8.0)) (pair 7.0 8.0))
(if (= (concat (pair 1.0 2.0) (triple 3.0 4.0 5.0)) (append3 (pair 1.0 2.0) 3.0 4.0 5.0))
(if (= (take (triple 10.0 20.0 30.0) -4) (empty))
(if (= (take (triple 10.0 20.0 30.0) 2) (pair 10.0 20.0))
(if (= (take (pair 10.0 20.0) 9) (pair 10.0 20.0))
(if (= (drop (triple 10.0 20.0 30.0) -4) (triple 10.0 20.0 30.0))
(if (= (drop (triple 10.0 20.0 30.0) 2) (singleton 30.0))
(if (= (drop (pair 10.0 20.0) 9) (empty))
(if (= (reverse (empty)) (empty))
(= (reverse (append3 (pair 10.0 20.0) 30.0 40.0 50.0)) (append3 (pair 50.0 40.0) 30.0 20.0 10.0))
false)
false)
false)
false)
false)
false)
false)
false)
false))
(fn imported_subvec_helper_ok () -> bool
(let original (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(if (= (subvec original -1 2) (empty))
(if (= (subvec original 3 3) (empty))
(if (= (subvec original 9 10) (empty))
(if (= (subvec original 2 99) (triple 30.0 40.0 50.0))
(if (= (subvec original 1 4) (triple 20.0 30.0 40.0))
(= original (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
false)
false)
false)
false)
false))
(fn imported_insert_helper_ok () -> bool
(let values (vec f64) (triple 10.0 20.0 30.0))
(if (= (insert_at values 1 99.0) (append2 (pair 10.0 99.0) 20.0 30.0))
(if (= (insert_at values 3 99.0) (append values 99.0))
(if (= values (triple 10.0 20.0 30.0))
(if (= (insert_at values -1 99.0) values)
(= (insert_at values 4 99.0) values)
false)
false)
false)
false))
(fn imported_insert_range_helper_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let inserted (vec f64) (pair 77.0 88.0))
(if (= (insert_range values -1 inserted) values)
(if (= (insert_range values 2 inserted) (append3 (append2 (pair 10.0 20.0) 77.0 88.0) 30.0 40.0 50.0))
(if (= (insert_range values 5 inserted) (append2 (append2 (triple 10.0 20.0 30.0) 40.0 50.0) 77.0 88.0))
(if (= values (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(if (= inserted (pair 77.0 88.0))
(= (insert_range values 6 inserted) values)
false)
false)
false)
false)
false))
(fn imported_replace_helper_ok () -> bool
(if (= (replace_at (triple 10.0 20.0 30.0) 1 99.0) (triple 10.0 99.0 30.0))
(if (= (replace_at (triple 10.0 20.0 30.0) -1 99.0) (triple 10.0 20.0 30.0))
(= (replace_at (pair 10.0 20.0) 2 99.0) (pair 10.0 20.0))
false)
false))
(fn imported_replace_range_helper_ok () -> bool
(let original (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(let replacement (vec f64) (pair 77.0 88.0))
(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 10.0 20.0) 77.0 88.0))
(if (= (replace_range original 1 4 replacement) (append2 (pair 10.0 77.0) 88.0 50.0))
(if (= original (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(= replacement (pair 77.0 88.0))
false)
false)
false)
false)
false)
false)
false))
(fn imported_remove_helper_ok () -> bool
(let original (vec f64) (triple 10.0 20.0 30.0))
(let removed_middle (vec f64) (remove_at original 1))
(if (= removed_middle (pair 10.0 30.0))
(if (= (len removed_middle) 2)
(if (= (remove_at original 0) (pair 20.0 30.0))
(if (= (remove_at original 2) (pair 10.0 20.0))
(if (= original (triple 10.0 20.0 30.0))
(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 f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(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 10.0 20.0))
(if (= (remove_range original 1 4) (pair 10.0 50.0))
(= original (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
false)
false)
false)
false)
false)
false))
(fn imported_real_program_helpers_ok () -> bool
(let values (vec f64) (append2 (triple 10.0 20.0 30.0) 40.0 50.0))
(if (= (original_len_after_append) 0)
(if (contains values 20.0)
(if (contains values 99.0)
false
(= (sum values) 150.0))
false)
false))
(fn helpers_all_ok () -> bool
(if (= (imported_empty_length) 0)
(if (= (imported_pair_index) 41.0)
(if (imported_builder_helpers_ok)
(if (imported_query_helpers_ok)
(if (imported_option_query_helpers_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))
(test "explicit std vec_f64 empty len facade"
(= (imported_empty_length) 0))
(test "explicit std vec_f64 direct at facade"
(= (imported_pair_index) 41.0))
(test "explicit std vec_f64 builder helpers"
(imported_builder_helpers_ok))
(test "explicit std vec_f64 query helpers"
(imported_query_helpers_ok))
(test "explicit std vec_f64 option query helpers"
(imported_option_query_helpers_ok))
(test "explicit std vec_f64 starts_with helper"
(imported_starts_with_helper_ok))
(test "explicit std vec_f64 ends_with helper"
(imported_ends_with_helper_ok))
(test "explicit std vec_f64 without_suffix helper"
(imported_without_suffix_helper_ok))
(test "explicit std vec_f64 without_prefix helper"
(imported_without_prefix_helper_ok))
(test "explicit std vec_f64 transform helpers"
(imported_transform_helpers_ok))
(test "explicit std vec_f64 subvec helper"
(imported_subvec_helper_ok))
(test "explicit std vec_f64 insert helper"
(imported_insert_helper_ok))
(test "explicit std vec_f64 insert range helper"
(imported_insert_range_helper_ok))
(test "explicit std vec_f64 replace helper"
(imported_replace_helper_ok))
(test "explicit std vec_f64 replace range helper"
(imported_replace_range_helper_ok))
(test "explicit std vec_f64 remove helper"
(imported_remove_helper_ok))
(test "explicit std vec_f64 remove range helper"
(imported_remove_range_helper_ok))
(test "explicit std vec_f64 real program helpers"
(imported_real_program_helpers_ok))
(test "explicit std vec_f64 helpers all"
(helpers_all_ok))
(fn main () -> i32
(if (helpers_all_ok)
42
1))