diff -r 34feeb53c0ba -r 0315d9983cd0 main_marking3/re_test.sh --- a/main_marking3/re_test.sh Sun Jan 15 10:58:13 2023 +0000 +++ b/main_marking3/re_test.sh Sat Mar 11 22:01:53 2023 +0000 @@ -27,11 +27,11 @@ # functional tests function scala_assert { - (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) } function scala_assert_thirty { - (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) + (ulimit -t 40; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null) } # purity test @@ -84,14 +84,14 @@ if [ $tsts -eq 0 ] then - echo -e "re.scala has case classes for ALTs and SEQs?" >> $out + echo -e "re.scala has case classes for ALTs and SEQs?" | tee -a $out if (scala_assert "re.scala" "re_test0.scala") then - echo -e " --> passed" >> $out + echo -e " --> passed" | tee -a $out tsts=$(( 0 )) else - echo -e " --> FAIL (make sure the case clases are as given in the template)" >> $out + echo -e " --> FAIL" | tee -a $out tsts=$(( 1 )) fi else @@ -99,7 +99,7 @@ fi -### re1 test +### re1 nullable test if [ $tsts -eq 0 ] then @@ -111,22 +111,24 @@ echo -e " nullable(ONE ~ ONE) == true" | tee -a $out echo -e " nullable(ONE ~ CHAR('a')) == false" | tee -a $out echo -e " nullable(STAR(ZERO)) == true" | tee -a $out + echo -e " nullable(ALTs(List(ONE, CHAR('a'), ZERO))) == true" | tee -a $out + echo -e " nullable(SEQs(List(ONE, ALTs(List(ONE, CHAR('a'), ZERO)), STAR(ZERO)))) == true" | tee -a $out if (scala_assert "re.scala" "re_test1.scala") then - echo -e " --> success" | tee -a $out + echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out marks=$(( marks + 0.5 )) else echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out fi fi -### re2 test +### re2 der test if [ $tsts -eq 0 ] then echo -e " der('a', ZERO | ONE) == (ZERO | ZERO)" | tee -a $out - echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), ONE)" | tee -a $out + echo -e " der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALT((ONE | ZERO) ~ CHAR('a'), SEQs(List(ONE)))" | tee -a $out echo -e " der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a')" | tee -a $out echo -e " der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a')))" | tee -a $out echo -e " der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a')))" | tee -a $out @@ -137,24 +139,83 @@ echo -e " der('c', r0) == (ZERO ~ \"b\") ~ \"c\"" | tee -a $out echo -e "" | tee -a $out echo -e " val r1 = (ONE ~ \"b\") ~ \"c\"" | tee -a $out - echo -e " der('a', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out - echo -e " der('b', r1) == ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out - echo -e " der('c', r1) == ((ZERO ~ \"b\") | ZERO) ~ \"c\"" | tee -a $out + echo -e " der('a', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out + echo -e " der('b', r1) == ((ZERO ~ \"b\") | SEQs(List(ONE))) ~ \"c\"" | tee -a $out + echo -e " der('c', r1) == ((ZERO ~ \"b\") | SEQs(List(ZERO))) ~ \"c\"" | tee -a $out echo -e "" | tee -a $out echo -e " val r2 = ((ZERO ~ \"b\") | ONE) ~ \"c\"" | tee -a $out - echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out - echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ZERO)" | tee -a $out - echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | ONE)" | tee -a $out + echo -e " der('a', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out + echo -e " der('b', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ZERO)))" | tee -a $out + echo -e " der('c', r2) == ((((ZERO ~ \"b\") | ZERO) ~ \"c\") | SEQs(List(ONE)))" | tee -a $out if (scala_assert "re.scala" "re_test2.scala") then - echo -e " --> success" | tee -a $out + echo -e " --> success (+ 1 Mark)\n" | tee -a $out marks=$(( marks + 1.0 )) else echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out fi fi +### re3 denest test + +if [ $tsts -eq 0 ] +then + echo -e " denest(List(ONE, ZERO, ALTs(List(ONE, CHAR('a'))))) == List(ONE, ONE, CHAR('a'))" | tee -a $out + echo -e " denest(List(ONE ~ ONE, ZERO, ZERO | ONE)) == List(ONE ~ ONE, ZERO, ONE)" | tee -a $out + + if (scala_assert "re.scala" "re_test4.scala") + then + echo -e " --> success (+ 1 Mark)\n" | tee -a $out + marks=$(( marks + 1.0 )) + else + echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + fi +fi + +### re3a flts test + +if [ $tsts -eq 0 ] +then + echo -e " flts(Nil) == Nil" | tee -a $out + echo -e " flts(ZERO::ZERO::Nil) == List(ZERO)" | tee -a $out + echo -e " flts(ZERO::ONE::ZERO::ONE::Nil) == List(ZERO)" | tee -a $out + echo -e " flts(ONE::ALTs(List(ONE))::ONE::Nil) == List(ALTs(List(ONE)))" | tee -a $out + echo -e " flts(ONE::ALTs(List(ONE))::ONE::ALTs(List(ONE))::Nil) == List(ALTs(List(ONE)), ALTs(List(ONE)))" | tee -a $out + echo -e " flts(List(CHAR('a'), ONE, ONE, CHAR('b')), Nil) == List(CHAR('a'), CHAR('b'))" | tee -a $out + echo -e " flts(List(ONE ~ CHAR('a'), CHAR('b') ~ ONE), Nil) == List(ONE, CHAR('a'), CHAR('b'), ONE)" | tee -a $out + + if (scala_assert "re.scala" "re_test3a.scala") + then + echo -e " --> success (+ 1 Mark)\n" | tee -a $out + marks=$(( marks + 1.0 )) + else + echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out + fi +fi + +### re-smart test + +if [ $tsts -eq 0 ] +then + echo -e " SEQs_smart(Nil) == ONE" | tee -a $out + echo -e " SEQs_smart(List(ZERO)) == ZERO" | tee -a $out + echo -e " SEQs_smart(List(CHAR('a'))) == CHAR('a')" | tee -a $out + echo -e " SEQs_smart(List(ONE ~ ONE)) == ONE ~ ONE" | tee -a $out + echo -e " SEQs_smart(List(ONE, ONE)) == SEQs(List(ONE, ONE))" | tee -a $out + echo -e " ALTs_smart(Nil) == ZERO" | tee -a $out + echo -e " ALTs_smart(List(ONE ~ ONE)) == ONE ~ ONE" | tee -a $out + echo -e " ALTs_smart(List(ZERO, ZERO)) == ALTs(List(ZERO, ZERO))" | tee -a $out + + if (scala_assert "re.scala" "re_test6.scala") + then + echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out + marks=$(( marks + 0.5 )) + else + echo -e " --> \n ONE TEST FAILED\n" | tee -a $out + fi +fi + ### re3 test if [ $tsts -eq 0 ] @@ -174,30 +235,12 @@ echo -e " simp((ZERO | ((ZERO | ZERO) | (ZERO | ZERO))) ~ ((ONE | ZERO) | ONE ) ~ (CHAR('a'))) == ZERO" | tee -a $out echo -e " simp(ALT(ONE | ONE, ONE | ONE)) == ONE" | tee -a $out echo -e " simp(ALT(ZERO | CHAR('a'), CHAR('a') | ZERO)) == CHAR('a')" | tee -a $out - echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE | CHAR('a'), CHAR('a') | ONE)" | tee -a $out - + echo -e " simp(ALT(ONE | CHAR('a'), CHAR('a') | ONE)) == ALT(ONE, CHAR('a'))" | tee -a $out + echo -e " simp(ALTs(Nil)) == ZERO" | tee -a $out + echo -e " simp(SEQs(List(CHAR('a')))) == CHAR('a')" | tee -a $out if (scala_assert "re.scala" "re_test3.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1.0 )) - else - echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out - fi -fi - -### re3a flts test - -if [ $tsts -eq 0 ] -then - echo -e " flts(Nil) == Nil" | tee -a $out - echo -e " flts(ZERO::ZERO::Nil) == Nil" | tee -a $out - echo -e " flts(ZERO::ONE::ZERO::ONE::Nil) == List(ONE, ONE)" | tee -a $out - echo -e " flts(ONE::ALTs(List(ONE))::ONE::Nil) == List(ONE, ONE, ONE)" | tee -a $out - echo -e " flts(ONE::ALTs(List(ONE))::ONE::ALTs(List(ONE))::Nil) == List(ONE, ONE, ONE, ONE)" | tee -a $out - - if (scala_assert "re.scala" "re_test3a.scala") - then - echo -e " --> success" | tee -a $out + echo -e " --> success (+ 1 Mark)\n" | tee -a $out marks=$(( marks + 1.0 )) else echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out @@ -205,13 +248,12 @@ fi - ### re4 test if [ $tsts -eq 0 ] then echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out - echo -e " ders((\"a\" * 5).toList,EVIL) == SEQ(SEQ(STAR(CHAR('a')),STAR(STAR(CHAR('a')))),CHAR('b'))" | tee -a $out + echo -e " ders((\"a\" * 5).toList,EVIL) == SEQs(List(STAR(CHAR('a')), STAR(STAR(CHAR('a'))), CHAR('b')))" | tee -a $out echo -e " ders(List('b'),EVIL) == ONE" | tee -a $out echo -e " ders(List('b','b'),EVIL) == ZERO" | tee -a $out echo -e " matcher(EVIL, \"a\" * 5 ++ \"b\") == true" | tee -a $out @@ -227,10 +269,10 @@ echo -e " matcher(ONE | CHAR('a'), \"\") == true" | tee -a $out echo -e " matcher(ONE | CHAR('a'), \"a\") == true" | tee -a $out - if (scala_assert "re.scala" "re_test4.scala") + if (scala_assert "re.scala" "re_test7.scala") then - echo -e " --> success" | tee -a $out - marks=$(( marks + 1.0 )) + echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out + marks=$(( marks + 0.5 )) else echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out fi @@ -238,18 +280,17 @@ ### re5 test - if [ $tsts -eq 0 ] then - echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out - echo -e " size(der('a', der('a', EVIL))) == 28" | tee -a $out - echo -e " size(der('a', der('a', der('a', EVIL)))) == 58" | tee -a $out - echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 8" | tee -a $out - echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 8" | tee -a $out + echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out + echo -e " size(der('a', der('a', EVIL))) == 36" | tee -a $out + echo -e " size(der('a', der('a', der('a', EVIL)))) == 83" | tee -a $out + echo -e " size(ders(\"aaaaaa\".toList, EVIL)) == 7" | tee -a $out + echo -e " size(ders((\"a\" * 50).toList, EVIL)) == 7" | tee -a $out - if (scala_assert "re.scala" "re_test5.scala") + if (scala_assert "re.scala" "re_test8.scala") then - echo -e " --> success" | tee -a $out + echo -e " --> success (+ 0.5 Marks)\n" | tee -a $out marks=$(( marks + 0.5 )) else echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out @@ -270,40 +311,19 @@ echo -e "" | tee -a $out echo -e " simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(20).next) == ONE" | tee -a $out echo -e " ... the Iterator produces a rexp of size 2097151" | tee -a $out + echo -e "" | tee -a $out + echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out + echo -e " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out + echo -e " matcher(EVIL, \"a\" * 1000000 ++ "b") == true" | tee -a $out START=$(date +%s) - if (scala_assert_thirty "re.scala" "re_test6.scala") + if (scala_assert_thirty "re.scala" "re_test9.scala") then END=$(date +%s) DIFF=$(( $END - $START )) - echo " This test ran for $DIFF seconds" | tee -a $out - echo -e " --> success" | tee -a $out - marks=$(( marks + 0.5 )) - else - END=$(date +%s) - DIFF=$(( $END - $START )) echo " This test ran for $DIFF seconds" | tee -a $out - echo -e " --> ONE OF THE TESTS FAILED\n" | tee -a $out - fi -fi - - -### re7 'power' test 2 - -if [ $tsts -eq 0 ] -then - echo -e " val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))" | tee -a $out - echo -e " matcher(EVIL, \"a\" * 1000000 ++ \"b\") == true" | tee -a $out - echo -e " matcher(EVIL, \"a\" * 1000000) == false" | tee -a $out - START=$(date +%s) - - if (scala_assert_thirty "re.scala" "re_test7.scala") - then - END=$(date +%s) - DIFF=$(( $END - $START )) - echo " This test ran for $DIFF seconds" | tee -a $out - echo -e " --> success" | tee -a $out - marks=$(( marks + 0.5 )) + echo -e " --> success (+ 1.0 Mark)\n" | tee -a $out + marks=$(( marks + 1.0 )) else END=$(date +%s) DIFF=$(( $END - $START )) @@ -314,6 +334,8 @@ + + ## final marks echo -e "Overall mark for Main Part 3 (Scala)" | tee -a $out printf " %0.1f\n" $marks | tee -a $out