From 07454039c7ed4384a679325e9cd75c1faaceb43d Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 7 Sep 2019 13:37:06 -0600 Subject: dump old assignment --- bin/problem-13.sh | 47 ----------------------------------------------- bin/problem-6.sh | 33 --------------------------------- bin/problem-7.sh | 24 ------------------------ test/problem-6.bats | 26 ++++---------------------- test/problem-7.bats | 27 --------------------------- 5 files changed, 4 insertions(+), 153 deletions(-) delete mode 100755 bin/problem-13.sh delete mode 100755 bin/problem-6.sh delete mode 100755 bin/problem-7.sh delete mode 100644 test/problem-7.bats diff --git a/bin/problem-13.sh b/bin/problem-13.sh deleted file mode 100755 index 1c431b8..0000000 --- a/bin/problem-13.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -banner() { - echo "Use one of the following options:" - echo " d: To display today's date and present time" - echo " l: To see the listing of files in your present working directory" - echo " w: To see who's logged in" - echo " q: To quit this program" - echo "Enter your option and hit :" -} - -quit() { - exit 0 -} -list() { - ls -} -print_date() { - date -} -logged_in() { - who -} - -menu() { - read option - case "$option" in - d) print_date - ;; - l) list - ;; - w) logged_in - ;; - q) quit - ;; - esac -} - -main() { - while true; do - banner - menu - done - quit -} - -main diff --git a/bin/problem-6.sh b/bin/problem-6.sh deleted file mode 100755 index 2eff10b..0000000 --- a/bin/problem-6.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -validate_input() { - invalid=0 - regex='^[0-9]+$' - - for i in "$@"; do - if ! [[ $i =~ $regex ]]; then - echo "error: \"$i\" is not a number" >&2 - invalid=1 - fi - done - - if [ $invalid -eq 1 ]; then - exit 1 - fi -} - -print_results() { - sum=0 - - printf "squares:" - for i in "$@"; do - sum=$((sum + $i)) - printf " $(($i * $i))" - done - printf "\n" - echo "sum: $sum" -} - -validate_input $@ -print_results $@ -exit 0 diff --git a/bin/problem-7.sh b/bin/problem-7.sh deleted file mode 100755 index 8cb15ce..0000000 --- a/bin/problem-7.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -if [ $# -eq 0 ]; then - echo "error: a hostname is required" >&2 - exit 1 -fi - -check() { - destination="$1" - host=$(host "$1" | grep 'has address') - ip=$(echo "$host" | cut -d' ' -f4) - ping -c1 $ip > /dev/null 2>&1 - - if [ $? -eq 0 ]; then - echo "$1" is on the network - else - echo "$1" is NOT on the network - fi -} - -for i in "$@"; do - check "$i" -done -exit 0 diff --git a/test/problem-6.bats b/test/problem-6.bats index acb685a..ff5ceb4 100644 --- a/test/problem-6.bats +++ b/test/problem-6.bats @@ -8,31 +8,13 @@ load test_helper } @test "invoke with a single integer" { - run problem-6.sh 2 + run echo 'hello' - assert_success $'squares: 4\nsum: 2' -} - -@test "invoke with multiple integers" { - run problem-6.sh 1 2 3 4 5 6 7 8 9 10 - - assert_success $'squares: 1 4 9 16 25 36 49 64 81 100\nsum: 55' + assert_success $'hello' } @test "invoke with single non-numeric" { - run problem-6.sh "oops" - - assert_failure $'error: "oops" is not a number' -} - -@test "invoke with multiple non-numeric" { - run problem-6.sh "first" "second" - - assert_failure $'error: "first" is not a number\nerror: "second" is not a number' -} - -@test "invoke with mixed numeric and non-numeric" { - run problem-6.sh "oops" 10 "invalid" + run rm blah - assert_failure $'error: "oops" is not a number\nerror: "invalid" is not a number' + assert_failure $'rm: blah: No such file or directory' } diff --git a/test/problem-7.bats b/test/problem-7.bats deleted file mode 100644 index 4cab203..0000000 --- a/test/problem-7.bats +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -#@test "invoke with a host on the network" { - #run problem-7.sh localhost - - #assert_success "localhost is on the network" -#} - -@test "invoke with a host not on the network" { - run problem-7.sh unknown - - assert_success "unknown is NOT on the network" -} - -@test "invoke without a hostname argument" { - run problem-7.sh - - assert_failure "error: a hostname is required" -} - -#@test "invoke with multiple hostnames" { - #run problem-7.sh localhost invalid - - #assert_success $'localhost is on the network\ninvalid is NOT on the network' -#} -- cgit v1.2.3