-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Convert to Lib tests #373
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# The following comments should help you get started: | ||
# - Bash is flexible. You may use functions or write a "raw" script. | ||
# | ||
# - Complex code can be made easier to read by breaking it up | ||
# into functions, however this is sometimes overkill in bash. | ||
# | ||
# - You can find links about good style and other resources | ||
# for Bash in './README.md'. It came with this exercise. | ||
# | ||
# Example: | ||
# # other functions here | ||
# # ... | ||
# # ... | ||
# | ||
# main () { | ||
# # your main function code here | ||
# } | ||
# | ||
# # call main with all of the positional arguments | ||
# main "$@" | ||
# | ||
# *** PLEASE REMOVE THESE COMMENTS BEFORE SUBMITTING YOUR SOLUTION *** | ||
equilateral() { | ||
echo 'unimplemented!' | ||
} | ||
|
||
isosceles() { | ||
echo 'unimplemented!' | ||
} | ||
|
||
scalene() { | ||
echo 'unimplemented!' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
# get user code | ||
source triangle.sh | ||
|
||
# Test returns true if the triangle is equilateral | ||
|
||
@test "all sides are equal, equilateral" { | ||
#[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 2 2 2 | ||
run equilateral 2 2 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a fan of exporting a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that it is a library I think main here is not right, but I could be convinced that a managing function has its place for namespacing. This also depends on how our other endeavors into namespacing fare. If you have some ideas for this exercise please feel free to make a PR to this branch on my fork. If you would prefer I am interested in making a new branch on the base repo for getting through this ordeal. I want to know other contributor opinions first though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you can make your own PR for triangle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment thread is getting to the heart of how we want to manage name-spacing in our bash libs.
Does anyone know of any common idioms or best practice guidelines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the world of bash library modules is all cowboys. We should see if Gnu org has any specification. I learned that functions may have The only problem I have is that my syntax highlighters get confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I did some more tests. I am not against setting v4.2 as a requirement for the track. Hell, I am on v5.0.7, but I would not make this requirement all on my own. If we decide against enforcing a minimum Bash version, then I see no other way to namespace the functions than by using an module access function. In order for this not to confuse students it should be present in the stub. We would need to decide if we write the whole thing, so they don't have to worry about it or not. Then we are left with the decision about how to name the parts it calls. Good naming convention would then make the former API functions internal and they should be preceded by a While I think that If it makes us feel any better. Golang's tests are in the same packagespace as the code, so all of the functions are called without namespacing. Also, our namespacing ideas were never going to solve issue of set options colliisions with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @issacg I guess we were typing at the same time 🤣 It seems we both came to the same conclusion (although I am very verbose as usual). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking around at other languages like Python and Ruby it is very evident tha no one else is worrying about this (but in their languages those functions will be namespaced once they are imported somewhere). That just isn't the way of life here 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note bash 3 (or, at least 3.2.57) supports space::func just fine. While we may not want to enforce bash 4+, I think it's fair to expect bash 3 or newer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for checking. |
||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "any side is unequal" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 2 3 2 | ||
run equilateral 2 3 2 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "no sides are equal, equilateral" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 5 4 6 | ||
run equilateral 5 4 6 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "all zero sides is not a triangle" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 0 0 0 | ||
run equilateral 0 0 0 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
@@ -34,7 +37,7 @@ | |
|
||
@test "sides may be floats, equilateral" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh equilateral 0.5 0.5 0.5 | ||
run equilateral 0.5 0.5 0.5 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
@@ -43,56 +46,56 @@ | |
|
||
@test "last two sides are equal" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 3 4 4 | ||
run isosceles 3 4 4 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "first two sides are equal" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 4 4 3 | ||
run isosceles 4 4 3 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "first and last sides are equal" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 4 3 4 | ||
run isosceles 4 3 4 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "equilateral triangles are also isosceles" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 4 4 4 | ||
run isosceles 4 4 4 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "no sides are equal, isosceles" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 2 3 4 | ||
run isosceles 2 3 4 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "first triangle inequality violation" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 1 1 3 | ||
run isosceles 1 1 3 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "second triangle inequality violation" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 1 1 3 | ||
run isosceles 1 1 3 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "third triangle inequality violation" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 1 1 3 | ||
run isosceles 1 1 3 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
@@ -101,7 +104,7 @@ | |
|
||
@test "sides may be floats, isosceles" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh isosceles 0.5 0.4 0.5 | ||
run isosceles 0.5 0.4 0.5 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
@@ -110,28 +113,28 @@ | |
|
||
@test "no sides are equal, scalene" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh scalene 5 4 6 | ||
run scalene 5 4 6 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
||
@test "all sides are equal, scalene" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh scalene 4 4 4 | ||
run scalene 4 4 4 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "two sides are equal" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh scalene 4 4 3 | ||
run scalene 4 4 3 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
||
@test "may not violate triangle inequality" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh scalene 7 3 2 | ||
run scalene 7 3 2 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "false" ]] | ||
} | ||
|
@@ -140,7 +143,7 @@ | |
|
||
@test "sides may be floats, scalene" { | ||
[[ $BATS_RUN_SKIPPED == true ]] || skip | ||
run bash triangle.sh scalene 0.5 0.4 0.6 | ||
run scalene 0.5 0.4 0.6 | ||
[[ $status -eq 0 ]] | ||
[[ $output == "true" ]] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ "$#" -eq 0 ]; then | ||
person="you" | ||
else | ||
person="$1" | ||
fi | ||
|
||
echo "One for $person, one for me." | ||
two_fer () { | ||
echo "One for ${1:-you}, one for me." | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
# The following comments should help you get started: | ||
# - Bash is flexible. You may use functions or write a "raw" script. | ||
# | ||
# - Complex code can be made easier to read by breaking it up | ||
# into functions, however this is sometimes overkill in bash. | ||
# | ||
# - You can find links about good style and other resources | ||
# for Bash in './README.md'. It came with this exercise. | ||
# | ||
# Example: | ||
# # other functions here | ||
# # ... | ||
# # ... | ||
# | ||
# main () { | ||
# # your main function code here | ||
# } | ||
# | ||
# # call main with all of the positional arguments | ||
# main "$@" | ||
# | ||
# *** PLEASE REMOVE THESE COMMENTS BEFORE SUBMITTING YOUR SOLUTION *** | ||
two_fer () { | ||
echo 'unimplemented!' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(( $1 == 0 )) && ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are very right about that.
At least I upgraded it from
[]
😂