#help with Hamming bash script test 12

12 messages · Page 1 of 1 (latest)

sullen nacelle
#

#!/usr/bin/env bash

var1=$1
var2=$2
n=0

if [[ "$#" -eq 0 ]] || [[ "$#" -eq 1 ]]
then 
    echo "Usage: hamming.sh <string1> <string2>"
    exit 1

elif [[ $var1 == "" ]] && [[ $var2 == "" ]]
then
    echo 0

# 'single letter identical strands'
elif [[ $var1 == $var2 ]] && [[ ${#var1} -eq 1 ]] && [[ ${#var2} -eq 1 ]]
then
    echo 0

# 'single letter different strands'
elif [[ $var1 != $var2 ]] && [[ ${#var1} -eq 1 ]] && [[ ${#var2} -eq 1 ]]
then    
    echo 1

# 'long identical strands'
elif [[ $var1 == $var2 ]]
then 
    echo 0 

# 'disallow first strand longer'
elif [[ ${#var1} -gt ${#var2} ]]
then
    echo "strands must be of equal length"
    exit 22

# 'disallow second strand longer'
elif [[ ${#var1} -lt ${#var2} ]]
then
    echo "strands must be of equal length"
    exit 22

elif [[ ${#var1} -eq ${#var2} ]] && [[ ${#var1} -gt 1 ]] && [[ ${#var2} -gt 1 ]] && [[ $var1 != $var2 ]]
then 
    for ((i=0;i<${#var1};i++))
    do
        letter1=${var1:$i:1}
        letter2=${var2:$i:1}
        if [[ $letter1 != "$letter2" ]]
        then
            ((n++))
        fi
    done
    echo $n

fi
true pineBOT
thick coral
#

What is the error message?

sullen nacelle
#

TEST FAILURE
(from function assert_output' in file bats-extra.bash, line 394, in test file hamming.bats, line 93) assert_output "1"' failed

-- output differs --
expected : 1
actual : 0

thick coral
#

Does that also show what command was run? What the input is?

#

If not, you can find it in the test file, line 93

sullen nacelle
thick coral
#

Also, please read the bot message and use codeblocks

#

What's your code output for those inputs? Do you understand why? What should it output? Do you understand why?

#

See also, debugging steps: #programming message

#

Figured it out?

sullen nacelle
#

in my understanding my code does not handles wiledcard correctly