This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Set.{deleteWith; intersection; difference}, Map.delete (#17)
* Update dependencies and remove ContaintersPrelude * Use Maybe functor from stdlib * Add Set.{deleteWith; intersection; difference}, Map.delete Refactors tests
- Loading branch information
1 parent
186227a
commit 608fd84
Showing
15 changed files
with
117 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
--- the functions here should be eventually put in the stdlib | ||
module Data.Tmp; | ||
|
||
import ContainersPrelude open; | ||
import Stdlib.Prelude open; | ||
import Stdlib.Trait open; | ||
|
||
printNatListLn : List Nat → IO | ||
| nil := printStringLn "nil" | ||
| (x :: xs) := printNat x >>> printString " :: " >>> printNatListLn xs; | ||
|
||
mapMaybe {A B} (f : A -> B) : Maybe A -> Maybe B | ||
| nothing := nothing | ||
| (just a) := just (f a); | ||
|
||
isJust {A} : Maybe A -> Bool | ||
| nothing := false | ||
| (just _) := true; |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# This file was autogenerated by Juvix version 0.6.4. | ||
# This file was autogenerated by Juvix version 0.6.5. | ||
# Do not edit this file manually. | ||
|
||
version: 2 | ||
checksum: 64d7d399b724977d770547857b6f074a7a8c5fd4d82b5fec029a307c1ff286b9 | ||
checksum: 84b86822b505189000d4de6ff4193143f40a64cd5a7a59c7ab8bf26c89f1891f | ||
dependencies: | ||
- git: | ||
name: anoma_juvix-stdlib | ||
ref: 16211500dc59a944f851fbaeeef703fdd09163fa | ||
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80 | ||
url: https://github.com/anoma/juvix-stdlib | ||
dependencies: [] |
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 |
---|---|---|
@@ -1,45 +1,86 @@ | ||
module Test.AVL; | ||
|
||
import Test.JuvixUnit open; | ||
import Juvix.Builtin.V1 open; | ||
import Stdlib.System.IO.Base open; | ||
import Stdlib.System.IO.String open; | ||
import Stdlib.Data.Pair open; | ||
import Stdlib.Data.List.Base open; | ||
import Stdlib.Prelude open; | ||
|
||
import Data.Set.AVL open; | ||
import | ||
Data.Set.AVL open; | ||
|
||
type Box := mkBox {b : Nat}; | ||
|
||
instance | ||
BoxOrdI : Ord Box := mkOrd (Ord.cmp on Box.b); | ||
|
||
--- Test for size and balance. | ||
mkTests : Pair String (Pair Nat (AVLTree Nat)) -> List Test | ||
| (title, len, s) := | ||
mkTests {A} : TestDescr A -> List Test | ||
| mkTestDescr@{testTitle; testLen; testSet} := | ||
let | ||
mkTitle : String -> String | ||
| m := title ++str " " ++str m; | ||
| m := testTitle ++str " " ++str m; | ||
sizeMsg : String := "sizes do not match"; | ||
balanceMsg : String := "not balanced"; | ||
in [ testCase (mkTitle "size") (assertEqual sizeMsg (size s) len) | ||
; testCase (mkTitle "balanced") (assertTrue balanceMsg (isBalanced s)) | ||
in [ testCase (mkTitle "size") (assertEqual sizeMsg (size testSet) testLen) | ||
; testCase (mkTitle "balanced") (assertTrue balanceMsg (isBalanced testSet)) | ||
]; | ||
|
||
TestDescr : Type := Pair String (Pair Nat (AVLTree Nat)); | ||
type TestDescr (A : Type) := | ||
mkTestDescr { | ||
testTitle : String; | ||
testLen : Nat; | ||
testSet : AVLTree A | ||
}; | ||
|
||
s1-tree : AVLTree Nat := fromList [1; 2; 8; 3; 3; 2; 9]; | ||
|
||
s2-tree : AVLTree Nat := fromList [1; 3; 0; 4; 4; 8; 2]; | ||
|
||
s1 : TestDescr Nat := mkTestDescr "s1" 5 s1-tree; | ||
|
||
s1 : TestDescr := "s1", 5, fromList [1; 2; 8; 3; 3; 2; 9]; | ||
s2 : TestDescr Nat := mkTestDescr "s2" 6 s2-tree; | ||
|
||
s2 : TestDescr := "s2", 6, fromList [1; 3; 0; 4; 4; 8; 2]; | ||
s2-delete : TestDescr Nat := | ||
mkTestDescr@{ | ||
testTitle := TestDescr.testTitle s2 ++str "-delete"; | ||
testLen := sub (TestDescr.testLen s2) 2; | ||
testSet := deleteMany [1; 8] (TestDescr.testSet s2) | ||
}; | ||
|
||
s2-delete : TestDescr := case s2 of t, l, s := t ++str "-delete", sub l 2, deleteMany [1; 8] s; | ||
s2-delete-with : TestDescr Box := | ||
mkTestDescr@{ | ||
testTitle := TestDescr.testTitle s2 ++str "-delete-with"; | ||
testLen := sub (TestDescr.testLen s2) 2; | ||
testSet := deleteManyWith Box.b [1; 8] (TestDescr.testSet s2 |> toList |> map mkBox |> fromList) | ||
}; | ||
|
||
s3 : TestDescr := "s3", 6, fromList [5; 4; 3; 2; 1; 0]; | ||
s3 : TestDescr Nat := | ||
mkTestDescr@{ | ||
testTitle := "s3"; | ||
testLen := 6; | ||
testSet := fromList [5; 4; 3; 2; 1; 0] | ||
}; | ||
|
||
s4 : TestDescr := "s4", 5, fromList [1; 2; 3; 4; 5]; | ||
s4 : TestDescr Nat := | ||
mkTestDescr@{ | ||
testTitle := "s4"; | ||
testLen := 5; | ||
testSet := fromList [1; 2; 3; 4; 5] | ||
}; | ||
|
||
tests : List Test := | ||
[testCase "s1-member" (assertTrue "member? 3 s1" (member? 3 (snd (snd s1))))] | ||
[ testCase "s1-member" (assertTrue "member? 3 s1" (member? 3 s1-tree)) | ||
; testCase | ||
"s1-s2-intersection" | ||
(assertEqual | ||
"intersection s1-tree s2-tree" | ||
(intersection s1-tree s2-tree) | ||
(fromList [1; 2; 3; 8])) | ||
; testCase | ||
"s1-s2-difference" | ||
(assertEqual "difference s1-tree s2-tree" (difference s1-tree s2-tree) (fromList [9])) | ||
] | ||
++ concatMap mkTests [s1; s2; s3; s4; s2-delete]; | ||
|
||
suite : TestSuite := testSuite "AVL Set" tests; | ||
|
||
main : IO := | ||
printStringLn (pretty (snd (snd s1))) | ||
>>> printStringLn (prettyDebug (snd (snd s1))) | ||
>>> runTestSuite suite; | ||
printStringLn (pretty s1-tree) >>> printStringLn (prettyDebug s1-tree) >>> runTestSuite suite; |
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
# This file was autogenerated by Juvix version 0.6.4. | ||
# This file was autogenerated by Juvix version 0.6.5. | ||
# Do not edit this file manually. | ||
|
||
version: 2 | ||
checksum: 13869df5ec05e9541007e466b9ccb3cb9dfab76e0a1387a2d79b58c33f959725 | ||
checksum: f08d729e734185158847c6199dcf859238b1edc267f35f56d33eae0a195f1da5 | ||
dependencies: | ||
- git: | ||
name: anoma_juvix-stdlib | ||
ref: 16211500dc59a944f851fbaeeef703fdd09163fa | ||
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80 | ||
url: https://github.com/anoma/juvix-stdlib | ||
dependencies: [] | ||
- git: | ||
name: anoma_juvix-test | ||
ref: f7e822969fa82c510f38d6569a9b5ac7f1180221 | ||
ref: 12b72c6f91126f08e19ef183cc377bb86e629de9 | ||
url: https://github.com/anoma/juvix-test | ||
dependencies: | ||
- git: | ||
name: anoma_juvix-stdlib | ||
ref: 16211500dc59a944f851fbaeeef703fdd09163fa | ||
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80 | ||
url: https://github.com/anoma/juvix-stdlib | ||
dependencies: [] | ||
- path: ../ | ||
dependencies: | ||
- git: | ||
name: anoma_juvix-stdlib | ||
ref: 16211500dc59a944f851fbaeeef703fdd09163fa | ||
ref: 17a82dd466010b51924677b16a3f09a6c4c86a80 | ||
url: https://github.com/anoma/juvix-stdlib | ||
dependencies: [] |