wk5: Tests finished and check with screenshot
Co-authored-by: Dimitar Byalkov <CapitalRhino@users.noreply.github.com>
This commit is contained in:
@@ -63,3 +63,51 @@ testCollatzEven = repeatUntil myPredicate myCollatz [24] ==
|
||||
testCollatzOdd: Bool
|
||||
testCollatzOdd = repeatUntil myPredicate myCollatz [19] ==
|
||||
[1,2,4,8,16,5,10,20,40,13,26,52,17,34,11,22,44,88,29,58,19]
|
||||
|
||||
testMyPredicate: Bool
|
||||
testMyPredicate = myPredicate [1,2,4,8,16]
|
||||
|
||||
testDouble: Bool
|
||||
testDouble = double 2 == 4
|
||||
|
||||
testAbove100: Bool
|
||||
testAbove100 = above100 101
|
||||
|
||||
|
||||
testRepeatUntil1: Bool
|
||||
testRepeatUntil1 = repeatUntil above100 double 7 == 112
|
||||
|
||||
testRepeatUntil2: Bool
|
||||
testRepeatUntil2 = repeatUntil above100 ((+) 1) 42 == 101
|
||||
|
||||
testRepeatUntil3: Bool
|
||||
testRepeatUntil3 = repeatUntil above100 ((+) 10) 42 == 102
|
||||
|
||||
testRepeatUntil4: Bool
|
||||
testRepeatUntil4 = repeatUntil above100 ((*) 2) 42 == 168
|
||||
|
||||
|
||||
testLog100Base2: Bool
|
||||
testLog100Base2 = log 2 100 == 7 -- 2⁷ = 128
|
||||
|
||||
testLog81Base3: Bool
|
||||
testLog81Base3 = log 3 81 == 4 -- 3⁴ = 81%
|
||||
|
||||
testLog82Base3: Bool
|
||||
testLog82Base3 = log 3 82 == 5 -- 3⁴ = 81
|
||||
|
||||
testLog80Base3: Bool
|
||||
testLog80Base3 = log 3 80 == 4 -- 3⁴ = 81
|
||||
|
||||
testLog25Base5: Bool
|
||||
testLog25Base5 = log 5 25 == 2
|
||||
|
||||
testLog48Base6: Bool
|
||||
testLog48Base6 = log 6 48 == 3
|
||||
|
||||
|
||||
allHighOrderTests: List Bool
|
||||
allHighOrderTests = [testCollatzEven, testCollatzOdd, testMyPredicate, testDouble,
|
||||
testAbove100, testRepeatUntil1, testRepeatUntil2, testRepeatUntil3,
|
||||
testRepeatUntil4, testLog100Base2, testLog81Base3, testLog82Base3, testLog80Base3, testLog25Base5, testLog48Base6]
|
||||
|
||||
|
@@ -22,15 +22,15 @@ print f =
|
||||
Const val ->
|
||||
String.fromInt val
|
||||
Poly func val ->
|
||||
"(" ++ print func ++ " ^ " ++ String.fromInt val ++ ")"
|
||||
"(" ++ print func ++ "^" ++ String.fromInt val ++ ")"
|
||||
Mult func1 func2 ->
|
||||
"(" ++ print func1 ++ " * " ++ print func2 ++ ")"
|
||||
"(" ++ print func1 ++ "*" ++ print func2 ++ ")"
|
||||
Div func1 func2 ->
|
||||
"(" ++ print func1 ++ " / " ++ print func2 ++ ")"
|
||||
"(" ++ print func1 ++ "/" ++ print func2 ++ ")"
|
||||
Plus func1 func2 ->
|
||||
"(" ++ print func1 ++ " + " ++ print func2 ++ ")"
|
||||
"(" ++ print func1 ++ "+" ++ print func2 ++ ")"
|
||||
Minus func1 func2 ->
|
||||
"(" ++ print func1 ++ " - " ++ print func2 ++ ")"
|
||||
"(" ++ print func1 ++ "-" ++ print func2 ++ ")"
|
||||
|
||||
eval: Float -> Function -> Float
|
||||
eval num f =
|
||||
|
@@ -91,3 +91,43 @@ simplifyHelp func =
|
||||
Minus (simplify left) (simplify right)
|
||||
_ ->
|
||||
func
|
||||
|
||||
-- Tests
|
||||
testPrintFunc: Bool
|
||||
testPrintFunc = print f == "(((3+x)*(x-(x^5)))+2)"
|
||||
|
||||
testPrintDerivFunc: Bool
|
||||
testPrintDerivFunc = print (derivative f) ==
|
||||
"((((0+1)*(x-(x^5)))+((3+x)*(1-(5*(x^4)))))+0)"
|
||||
|
||||
testPrintSimplifyDerivFunc: Bool
|
||||
testPrintSimplifyDerivFunc = print (simplify (derivative f)) ==
|
||||
"((x-(x^5))+((3+x)*(1-(5*(x^4)))))"
|
||||
|
||||
testDerivX: Bool
|
||||
testDerivX = derivative X == Const 1
|
||||
|
||||
testDerivConst: Bool
|
||||
testDerivConst = derivative (Const 5) == Const 0
|
||||
|
||||
testDerivPlus: Bool
|
||||
testDerivPlus = derivative (Plus X (Const 9)) == Plus (Const 1) (Const 0)
|
||||
|
||||
testDerivMult: Bool
|
||||
testDerivMult = derivative (Mult (Const 4) X) ==
|
||||
Plus (Mult (Const 0) X) (Mult (Const 4) (Const 1))
|
||||
|
||||
testDerivPolyX: Bool
|
||||
testDerivPolyX = derivative (Poly X 3) == Mult (Const 3) (Poly X 2)
|
||||
|
||||
testDerivPoly: Bool
|
||||
testDerivPoly = derivative (Poly (Const 4) 3) == (Poly (Const 0) 3)
|
||||
|
||||
testSimplePoly: Bool
|
||||
testSimplePoly = simplify (Poly (Const 0) 3) == Const 0
|
||||
|
||||
testSimpleRecursivePlus: Bool
|
||||
testSimpleRecursivePlus = simplify (Plus ((Mult (Const 1) X)) (Minus X (Const 0))) == (Plus X X)
|
||||
|
||||
allModelling2Tests: List Bool
|
||||
allModelling2Tests = [testPrintFunc, testPrintDerivFunc, testPrintSimplifyDerivFunc, testDerivX, testDerivConst, testDerivPlus, testDerivMult, testDerivPolyX, testDerivPoly, testSimplePoly, testSimpleRecursivePlus]
|
||||
|
BIN
wk5/src/Screenshot from 2024-03-22 23-29-57.png
Normal file
BIN
wk5/src/Screenshot from 2024-03-22 23-29-57.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Reference in New Issue
Block a user