Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ar.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 15 additions & 1 deletion tests/test_ar.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}
Loading