Skip to content

Commit 8e0752a

Browse files
committed
Save.
1 parent fb292ea commit 8e0752a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

bin/add

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
add() {
3+
IFS="," read -ra numbers <<< "$1"
4+
local sum=0
5+
lista=( "pippo" "pluto" "pape rino")
6+
for number in "${numbers[@]}"
7+
do
8+
((sum+=number))
9+
done
10+
echo "$sum"
11+
return
12+
}
13+
[[ $BASH_SOURCE == $0 ]] && add "$@"

script/test-all

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
stampa_risultato_dei_test() {
3+
if [[ $? == 0 ]]
4+
then
5+
tput setaf 2; echo "ALL PASSED"; tput sgr0
6+
else
7+
tput setaf 1; echo "SOME PROBLEMS"; tput sgr0
8+
fi
9+
}
10+
assert_equal() {
11+
echo "$1" > actual.txt
12+
echo "$2" > expected.txt
13+
diff -u expected.txt actual.txt
14+
}
15+
16+
source bin/add
17+
18+
assert_equal "0" "$(add "")"
19+
20+
assert_equal "1" "$(add 1)"
21+
assert_equal "2" "$(add 2)"
22+
23+
assert_equal "3" "$(add 1,2)"
24+
assert_equal "5" "$(add 2,3)"
25+
26+
assert_equal "8" "$(add 2,3,3)"
27+
assert_equal "10" "$(add 2,2,3,3)"
28+
29+
assert_equal "10" "$(bin/add 1,2,3,4)"
30+
assert_equal "" "$(source bin/add)"
31+
32+
stampa_risultato_dei_test

0 commit comments

Comments
 (0)