-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
146 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module LFCFPTestes where | ||
|
||
import LFCFP | ||
|
||
import Test.HUnit | ||
|
||
v5 = Valor 5 | ||
v3 = Valor 3 | ||
|
||
s1 = Soma v5 v3 | ||
|
||
s2 = Soma s1 v3 | ||
|
||
-- let x = 5 in x + x | ||
let01 = Let "x" (Valor 5) (Soma (Ref "x") (Ref "x")) | ||
|
||
-- let x = 5 in let y = 10 in x + y | ||
let02 = Let "x" (Valor 5) | ||
(Let "y" (Valor 10) (Soma (Ref "x") (Ref "y"))) | ||
|
||
-- let x = 5 in x + let x = 10 in x + 3 | ||
let03 = Let "x" (Valor 5) | ||
(Soma (Ref "x") (Let "x" (Valor 10) (Soma (Ref "x") (Valor 3)))) | ||
|
||
-- let x = 5 in let y = x in y | ||
let04 = Let "x" (Valor 5) | ||
(Let "y" (Ref "x") (Ref "y")) | ||
|
||
-- let x = 5 in let x = x in x | ||
let05 = Let "x" (Valor 5) | ||
(Let "x" (Ref "x") (Ref "x")) | ||
|
||
teste1 = TestCase (assertEqual "avaliar 5" 5 (toInt v5)) | ||
|
||
teste2 = TestCase (assertEqual "avaliar 5 + 3" 8 (toInt (avaliar s1 []))) | ||
|
||
teste3 = TestCase (assertEqual "avaliar (5 + 3) + 3" 11 (toInt (avaliar s2 []))) | ||
|
||
teste4 = TestCase (assertEqual "avaliar let x = 5 in x + x" 10 (toInt(avaliar let01 []))) | ||
|
||
teste5 = TestCase (assertEqual "avaliar let x = 5 in let y = 10 in x + y" 15 (toInt(avaliar let02 []))) | ||
|
||
teste6 = TestCase (assertEqual "avaliar let x = 5 in x + let x = 10 in x + 3" 18 (toInt(avaliar let03 []))) | ||
|
||
teste7 = TestCase (assertEqual "avaliar let x = 5 in let y = x in y" 5 (toInt(avaliar let04 []))) | ||
|
||
teste8 = TestCase (assertEqual "avaliar let x = 5 in let x = x in x" 5 (toInt(avaliar let05 []))) | ||
|
||
todosOsTestes = TestList [ teste1 | ||
, teste2 | ||
, teste3 | ||
, teste4 | ||
, teste5 | ||
, teste6 | ||
, teste7 | ||
, teste8 | ||
] | ||
|
||
executarTestes = runTestTT todosOsTestes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module LFLETestes where | ||
|
||
import LFLE02E | ||
|
||
import Test.HUnit | ||
|
||
inc :: DecFuncao | ||
inc = DecFuncao "inc" "x" (Soma (Ref "x") (Valor 1)) | ||
|
||
sqr :: DecFuncao | ||
sqr = DecFuncao "sqr" "x" (Multiplicacao (Ref "x") (Ref "x")) | ||
|
||
f :: DecFuncao | ||
f = DecFuncao "f" "p" (Ref "n") | ||
|
||
app1 :: Expressao | ||
app1 = Aplicacao "inc" (Valor 5) | ||
|
||
app2 :: Expressao | ||
app2 = Aplicacao "sqr" (Valor 5) | ||
|
||
let1 :: Expressao | ||
let1 = Let "x" (Valor 5) (Soma (Ref "x") (Ref "x")) | ||
|
||
let2 :: Expressao | ||
let2 = Let "x" (Valor 10) (Aplicacao "sqr" (Ref "x")) | ||
|
||
let3 :: Expressao | ||
let3 = Let "n" (Valor 5) (Aplicacao "f" (Valor 10)) | ||
|
||
let4 :: Expressao | ||
let4 = Let "x" (Valor 10) (Soma (Ref "x") (Let "x" (Valor 5) (Soma (Ref "x") (Valor 8)))) | ||
|
||
let5 :: Expressao | ||
let5 = Let "x" (Valor 10) | ||
(Soma (Let "x" (Valor 5) (Soma (Ref "x") (Valor 8))) (Ref "x")) | ||
|
||
|
||
amb = [inc, sqr, f] | ||
|
||
testeInc = TestCase (assertEqual "avaliar inc 5" 6 (avaliar app1 amb [])) | ||
|
||
testeSqr = TestCase (assertEqual "avaliar sqr 5" 25 (avaliar app2 amb [])) | ||
|
||
testeLet1 = TestCase (assertEqual "avaliar let x = 5 in x + x" 10 (avaliar let1 [] [])) | ||
|
||
testeLet2 = TestCase (assertEqual "avaliar let x = 10 in sqr x)" 100 (avaliar let2 amb [])) | ||
|
||
testeLet3 = TestCase (assertEqual "avaliar let n = 5 in f 10)" 5 (avaliar let3 amb [])) | ||
|
||
testeLet4 = TestCase (assertEqual "avaliar let x = 10 in x + (let x = 5 in x + 8)" 28 | ||
(avaliar let4 [] [])) | ||
|
||
testeLet5 = TestCase (assertEqual "avaliar let x = 10 in (let x = 5 in x + 8) + x" 28 | ||
(avaliar let5 [] [])) | ||
|
||
todosOsTestes = TestList [ testeInc | ||
, testeSqr | ||
, testeLet1 | ||
, testeLet2 | ||
, testeLet3 | ||
] | ||
|
||
executarTestes = runTestTT todosOsTestes |