-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Applicative GenT to use zipping
- Loading branch information
Showing
9 changed files
with
172 additions
and
14 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
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
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,24 @@ | ||
package hedgehog | ||
|
||
import hedgehog.core._ | ||
import hedgehog.predef._ | ||
|
||
/** | ||
* A simplified strict tree for testing trees with. | ||
* | ||
* FIXME We should consider introducing a parameter for Tree that lets us do this easily. | ||
*/ | ||
case class TTree[A](value: A, children: List[TTree[A]]) { | ||
|
||
def toTree: Tree[A] = | ||
Tree(value, Identity(LazyList.fromList(children.map(_.toTree)))) | ||
} | ||
|
||
object TTree { | ||
|
||
def fromTree[A](depth: Int, width: Int, t: Tree[A]): TTree[A] = | ||
if (depth <= 0) | ||
TTree(t.value, Nil) | ||
else | ||
TTree(t.value, t.children.value.toList(width).map(TTree.fromTree(depth - 1, width, _))) | ||
} |
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,33 @@ | ||
package hedgehog | ||
|
||
import hedgehog.runner._ | ||
|
||
object TreeTest extends Properties { | ||
|
||
def tests: List[Test] = | ||
List( | ||
example("applicative", testApplicative) | ||
, example("monad", testMonad) | ||
) | ||
|
||
def testApplicative: Result = { | ||
TTree.fromTree(100, 100, forTupled( | ||
TTree(1, List(TTree(2, List()))).toTree | ||
, TTree(3, List(TTree(4, List()))).toTree | ||
)) ==== TTree((1, 3), List( | ||
TTree((2, 3), List(TTree((2, 4), List()))) | ||
, TTree((1, 4), List(TTree((2, 4), List()))) | ||
)) | ||
} | ||
|
||
def testMonad: Result = { | ||
TTree.fromTree(100, 100, for { | ||
a <- TTree(1, List(TTree(2, List()))).toTree | ||
b <- TTree(3, List(TTree(4, List()))).toTree | ||
} yield (a, b) | ||
) ==== TTree((1, 3), List( | ||
TTree((2, 3), List(TTree((2, 4), List()))) | ||
, TTree((1, 4), List())) | ||
) | ||
} | ||
} |