Yes, you are correct in what you say about the sum. Either doing that or seeing whether the return line provided from the function is the same as the one in the testcase file. I know diff works for files but maybe I can use it for smaller cases.:rolleyes:
---------- Post updated at 03:04 AM ---------- Previous update was at 02:06 AM ----------
Okay, I'm at the point where I am trying to pass an argument(odd line) to the ./test program and it keeps saying "command not found." I am trying to get the return value and store it in a variable. If I just run ./test in the terminal and hit enter, the cursor goes to the next line and I can enter something. When I call ./test in this way inside a script, it doesn't call it like this does it? ./test 0 0 0
Hopefully not. I know some of this code is repetitive and needs cleaned up but I am just trying to figure out how to get a value back from this program. Once I do this I can compare the line I got back to the even line in the evens file. Sorry, I am kind of new to shell programming so my code may look bad.
set dir="$PWD/./test"
set dir2="$PWD/testcase.txt"
set ODD=""
set EVEN=""
set oddlines=`sed -n 1~2p $PWD/testcase.txt > ODD`
set evenlines=`awk NR%2==0 $PWD/testcase.txt > EVEN`
set odd="`cat $PWD/ODD`"
set even="`cat $PWD/EVEN`"
set FILERETURN=""
set i=1
set j=1
while ($i <= $#odd)
while ($j <= $#even)
FILERETURN=$dir "$odd[$i]"
echo FILERETURN
#echo $odd[$i]
#echo $even[$j]
@ i = $i + 1
@ j = $j + 1
end
end
---------- Post updated at 12:55 PM ---------- Previous update was at 03:04 AM ----------
Well, I've almost done it. I managed to pipe pipe odd lines in, send them to the program and put them into a return variable. I've compared them in terminal and I am getting what I want. All the test cases run and I get a 10/10, my only problem is the trailing command not found messages. I do not know why this is happening. It's probably something really small but I don't have enough experience to immediately see it. Any helpful hints as to why I'm getting "command not found." Is there something wrong with my if statement?
set dir="$PWD/./test"
set dir2="$PWD/testcase.txt"
set ODD=""
set EVEN=""
set oddlines=`sed -n 1~2p $PWD/testcase.txt > ODD`
set evenlines=`awk NR%2==0 $PWD/testcase.txt > EVEN`
set fodd=$PWD/ODD
set odd="`cat $PWD/ODD`"
set even="`cat $PWD/EVEN`"
set FILERETURN=""
set i=1
set j=1
set counttot=0
set countpass=0
while ($i <= $#odd)
while ($j <= $#even)
set FILERETURN=(`echo $odd[$i] | $dir`)
#echo $FILERETURN
#echo $even[$j]
if $FILERETURN == $even[$j]
@ countpass = $countpass + 1
endif
#echo $odd[$i]
#echo $even[$j]
@ counttot = $counttot + 1
@ i = $i + 1
@ j = $j + 1
end
end
echo "passed/total tests" $countpass "/" $counttot
rm ODD EVEN
The output in terminal I get when I run check.sh is the following:
% check.sh
-1: Command not found.
0: Command not found.
-1: Command not found.
-1: Command not found.
-1: Command not found.
-1: Command not found.
-1: Command not found.
0: Command not found.
passed/total tests 10 / 10