This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Fix trie lookup, added a test to ensure memoized function doesn't get… #9
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,12 +1,18 @@ | ||
module Test.Main where | ||
|
||
import Prelude | ||
import Data.Generic.Rep as G | ||
import Control.Monad.Eff (Eff) | ||
import Control.Monad.Eff.Console (CONSOLE, logShow) | ||
import Control.Monad.Eff.Exception (EXCEPTION) | ||
import Control.Monad.Eff.Random (RANDOM) | ||
import Control.Monad.Eff.Ref (REF, newRef, modifyRef, readRef) | ||
import Control.Monad.Eff.Unsafe (unsafePerformEff) | ||
import Data.Function.Memoize (class Tabulate, memoize, memoize2, gTabulate) | ||
import Data.Generic.Rep (class Generic) | ||
import Data.List ((:), length, singleton) | ||
import Data.String (take, drop) | ||
import Test.QuickCheck (quickCheck') | ||
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) | ||
|
||
data Diff a = Add a | Remove a | ||
|
||
|
@@ -18,12 +24,25 @@ data Ints | |
= Int1 Int | ||
| Int2 Int | ||
|
||
derive instance genericInts :: Generic Ints _ | ||
instance genericInts :: G.Generic Ints | ||
(G.Sum | ||
(G.Constructor "Int1" (G.Argument Int)) | ||
(G.Constructor "Int2" (G.Argument Int))) where | ||
to (G.Inl (G.Constructor (G.Argument x))) = Int1 x | ||
to (G.Inr (G.Constructor (G.Argument x))) = Int2 x | ||
from (Int1 x) = G.Inl (G.Constructor (G.Argument x)) | ||
from (Int2 x) = G.Inr (G.Constructor (G.Argument x)) | ||
|
||
instance tabulateInts :: Tabulate Ints where | ||
tabulate = gTabulate | ||
|
||
main :: forall eff. Eff (console :: CONSOLE | eff) Unit | ||
|
||
newtype SmallInt = SmallInt Int | ||
|
||
instance arbSmallInt :: Arbitrary SmallInt where | ||
arbitrary = SmallInt <<< (_ `mod` 1000) <$> arbitrary | ||
|
||
main :: forall eff. Eff (ref :: REF, console :: CONSOLE, random :: RANDOM, err :: EXCEPTION | eff) Unit | ||
main = do | ||
let fibonacciFast = go 0 1 | ||
where | ||
|
@@ -62,3 +81,13 @@ main = do | |
| otherwise -> smallest (Add (take 1 s2) : diff s1 (drop 1 s2)) | ||
(Remove (take 1 s1) : diff (drop 1 s1) s2) | ||
logShow $ diff "Hello, PureScript" "ello, PureScript!" | ||
|
||
called <- newRef 0 | ||
let fn x = 2 * x | ||
msin = memoize \n -> unsafePerformEff do | ||
modifyRef called (_ + 1) | ||
pure $ fn n | ||
quickCheck' 10000 $ \(SmallInt x) -> fn x == msin x | ||
ncalled <- readRef called | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! 😄 |
||
quickCheck' 1 $ ncalled < 2000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use |
||
pure unit |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please leave this as-is? It should build with the compiler in
master
.