示例#1
0
 public function testFromMaybeStringBugfix()
 {
     // TODO: move FuncTest
     $z = Nothing();
     $m = Just('printf');
     $this->assertEquals('a', fromMaybe('a', $z));
     $this->assertEquals('printf', fromMaybe('a', $m));
 }
示例#2
0
 public function testGuardAppend()
 {
     $f = function ($s, ...$eq) {
         return f(function ($s, $a, $b) {
             return fconst($s, guard($a === $b));
         }, $s, ...$eq);
     };
     $at = $f('a', 1, 1);
     $af = $f('a', 1, 2);
     $bt = $f('b', 2, 2);
     $bf = $f('b', 2, 3);
     $this->assertEquals(Just('a'), $at->cast(Nothing()));
     $this->assertEquals(Nothing(), $af->cast(Nothing()));
     $this->assertEquals(Just('b'), $bt->cast(Nothing()));
     $this->assertEquals(Nothing(), $bf->cast(Nothing()));
     $this->assertEquals(Nothing(), mappend($af, $bf)->cast(Nothing()));
     $this->assertEquals(Just('a'), mappend($at, $bf)->cast(Nothing()));
     $this->assertEquals(Just('b'), mappend($af, $bt)->cast(Nothing()));
     $this->assertEquals(Just('ab'), mappend($at, $bt)->cast(Nothing()));
     $this->assertEquals(Nothing(), mappend($f('a', 1), $f('b', 1), 2)->cast(Nothing()));
     $this->assertEquals(Just('a'), mappend($f('a', 2), $f('b', 1), 2)->cast(Nothing()));
     $this->assertEquals(Just('b'), mappend($f('a', 1), $f('b', 2), 2)->cast(Nothing()));
     $this->assertEquals(Just('ab'), mappend($f('a', 2), $f('b', 2), 2)->cast(Nothing()));
 }
示例#3
0
 public function testTreeMaybe()
 {
     $ret = $this->runSearch();
     $this->assertEquals(Just(3), mplus($ret, Nothing()));
 }