-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from tweag/tbagrel1/inspection-testing-make-elim
Add inspection tests to `Replicator.elim` and `V.{make,elim}`
- Loading branch information
Showing
8 changed files
with
108 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
-- rather than linear types). | ||
module Data.V.Linear | ||
( V, | ||
empty, | ||
consume, | ||
map, | ||
pure, | ||
|
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,31 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE LinearTypes #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# OPTIONS_GHC -O -dno-suppress-type-signatures -fplugin=Test.Tasty.Inspection.Plugin #-} | ||
|
||
module Test.Data.Replicator (replicatorInspectionTests) where | ||
|
||
import Data.Replicator.Linear (Replicator) | ||
import qualified Data.Replicator.Linear as Replicator | ||
import Prelude.Linear | ||
import Test.Tasty | ||
import Test.Tasty.Inspection | ||
|
||
replicatorInspectionTests :: TestTree | ||
replicatorInspectionTests = | ||
testGroup | ||
"Inspection testing of elim for Replicator" | ||
[$(inspectTest $ 'elim3 === 'manualElim3)] | ||
|
||
elim3 :: (a %1 -> a %1 -> a %1 -> [a]) %1 -> Replicator a %1 -> [a] | ||
elim3 f r = Replicator.elim f r | ||
|
||
manualElim3 :: (a %1 -> a %1 -> a %1 -> [a]) %1 -> Replicator a %1 -> [a] | ||
manualElim3 f r = | ||
Replicator.next r & \case | ||
(x, r') -> | ||
Replicator.next r' & \case | ||
(y, r'') -> | ||
Replicator.extract r'' & \case | ||
z -> f x y z |
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,42 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE LinearTypes #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# OPTIONS_GHC -O -dno-suppress-type-signatures -fplugin=Test.Tasty.Inspection.Plugin #-} | ||
|
||
module Test.Data.V (vInspectionTests) where | ||
|
||
import Data.V.Linear (V) | ||
import qualified Data.V.Linear as V | ||
import Prelude.Linear | ||
import Test.Tasty | ||
import Test.Tasty.Inspection | ||
|
||
vInspectionTests :: TestTree | ||
vInspectionTests = | ||
testGroup | ||
"Inspection testing of elim and make for V" | ||
[ $(inspectTest $ 'make3 === 'manualMake3), | ||
$(inspectTest $ 'elim3 ==- 'manualElim3) | ||
] | ||
|
||
make3 :: a %1 -> a %1 -> a %1 -> V 3 a | ||
make3 = V.make | ||
|
||
manualMake3 :: a %1 -> a %1 -> a %1 -> V 3 a | ||
manualMake3 x y z = V.cons x . V.cons y . V.cons z $ V.empty | ||
|
||
elim3 :: (a %1 -> a %1 -> a %1 -> [a]) %1 -> V 3 a %1 -> [a] | ||
elim3 f v = V.elim f v | ||
|
||
manualElim3 :: (a %1 -> a %1 -> a %1 -> [a]) %1 -> V 3 a %1 -> [a] | ||
manualElim3 f v = | ||
V.uncons v & \case | ||
(x, v') -> | ||
V.uncons v' & \case | ||
(y, v'') -> | ||
V.uncons v'' & \case | ||
(z, v''') -> | ||
V.consume v''' & \case | ||
() -> f x y z |