From 300861313d1947196c462981e3afc63f0c4a2fc9 Mon Sep 17 00:00:00 2001 From: Jesse Wattenbarger Date: Sun, 4 May 2025 09:12:35 -0400 Subject: [PATCH] Add test for ar::set --- ar.bash | 3 +-- tests/test_ar.bats | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ar.bash b/ar.bash index 781b4fa..c887aa6 100644 --- a/ar.bash +++ b/ar.bash @@ -299,7 +299,7 @@ ar::reverse() { ## @fn ar::set() -## @brief Turn array into a set array (no duplicates) +## @brief Create a set array from an array (no duplicates) ## @param arr The array to setify ## @param arr_set The array to write the result into ar::set() { @@ -382,7 +382,6 @@ ar::punion() { ## @param arr2 The second array name ## @params intersect_arr The array name to write the result to ar::intersection() { - echo "Not Implemented Yet" local -n arr1="$1" local -n arr2="$2" local -n intersect_arr="$3" diff --git a/tests/test_ar.bats b/tests/test_ar.bats index b735f0d..89649d7 100644 --- a/tests/test_ar.bats +++ b/tests/test_ar.bats @@ -35,7 +35,7 @@ setup() { ar::push expected salt pepper for ((i=0; i < arr_len; i++)); do [[ ${_starting_array[i]} == "${expected[i]}" ]] - done + done } @test "ar::index returns the index for the first occurence of value" { @@ -63,3 +63,17 @@ setup() { run ar::remove _starting_array beef [[ $status -eq 1 ]] } + +@test "ar::set turns an array into a set array" { + local expected_arr=(rice beans sausage) + local expected_len="${#expected_arr[@]}" + local starting_arr=(rice beans sausage rice) + local -a set_arr + ar::set starting_arr set_arr + local len="${#set_arr[@]}" + (( len == expected_len )) + # Order shouldn't matter + for ((i=0; i < arr_len; i++)); do + ar::in_set expected_arr "${set_arr[i]}" + done +}