Skip to content

Commit

Permalink
add test for DFA.invhomimage
Browse files Browse the repository at this point in the history
Obviously it would be a bad idea to mix `where` clauses from different tests, so naturally it's better to pull each out into it's own `Test ()` but there is still restructuring that needs to happen in the source files (see #1 ) so it would be wise to wait for that to happen before structuring all of the tests in a way which will depend on the current (soon to be old) structure.
  • Loading branch information
subttle authored Jun 1, 2019
1 parent 7fd324d commit 92a0992
Showing 1 changed file with 59 additions and 23 deletions.
82 changes: 59 additions & 23 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# OPTIONS_GHC -Wall #-}
-- Unfortunately, using Fin types breaks the warnings for incomplete patterns at this time
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE OverloadedStrings #-}

Expand All @@ -21,28 +23,62 @@ suite ∷ Test ()
suite = tests [ scope "DFA.empty" . expect $ Config.language DFA.empty == ([] [[Bool]])
, scope "DFA.epsilon" . expect $ Config.language DFA.epsilon == ([[]] [[Bool]])
, scope "DFA.literal" . expect $ Config.language (DFA.literal True) == [[True]]
-- https://math.stackexchange.com/questions/871662/finding-right-quotient-of-languages
, scope "DFA.rquotient" . expect $ and [ Config.accepts e3L1 [C, A, R, R, O, T]
, Config.accepts e3L2 [T]
, Config.accepts e3L2 [O, T]
, Config.accepts e3L1L2 [C, A, R, R, O]
, Config.accepts e3L1L2 [C, A, R, R]
, Prelude.take 2 (Config.language e3L1L2) == [[C, A, R, R], [C, A, R, R, O]]
]
, scope "DFA.quotient" . expect $ minimal `DFA.equal` (quotient minimal) && size' (useful (quotient minimal)) < size' (useful (minimal))
, scope "DFA.quotient" . expect $ minimal `DFA.equal` quotient minimal && size' (useful (quotient minimal)) < size' (useful (minimal))
, scope "DFA.toRE" . expect $ toRE by5 `RE.equivalent` by5'
, testDFArquotient
, testDFAinvhomimage
]
where e3L1 DFA FinAlpha
e3L1 = DFA { delta = δ
, q0 = 0
, fs = singleton 6
} where δ (0, C) = 1
δ (1, A) = 2
δ (2, R) = 3
δ (3, R) = 4
δ (4, O) = 5
δ (5, T) = 6
δ _ = 7
e3L2 = DFA.union (right e3L1 4) (DFA.literal T)
-- e3L2 = DFA.union (right e3L1 4) (right e3L1 5)
e3L1L2 = DFA.rquotient e3L1 e3L2

-- https://math.stackexchange.com/questions/871662/finding-right-quotient-of-languages
testDFArquotient Test ()
testDFArquotient = scope "DFA.rquotient" . expect $ and [ Config.accepts e3L1 [C, A, R, R, O, T]
, Config.accepts e3L2 [T]
, Config.accepts e3L2 [O, T]
, Config.accepts e3L1L2 [C, A, R, R, O]
, Config.accepts e3L1L2 [C, A, R, R]
, Prelude.take 2 (Config.language e3L1L2) == [[C, A, R, R], [C, A, R, R, O]]
]
where e3L1 DFA FinAlpha
e3L1 = DFA { delta = δ
, q0 = 0
, fs = singleton 6
} where δ (0, C) = 1
δ (1, A) = 2
δ (2, R) = 3
δ (3, R) = 4
δ (4, O) = 5
δ (5, T) = 6
δ _ = 7
e3L2 = DFA.union (right e3L1 4) (DFA.literal T)
-- e3L2 = DFA.union (right e3L1 4) (right e3L1 5)
e3L1L2 = DFA.rquotient e3L1 e3L2

testDFAinvhomimage Test ()
testDFAinvhomimage = scope "DFA.invhomimage" . expect $ DFA.invhomimage h slide22 `DFA.equal` expected
where -- slide 22 http://infolab.stanford.edu/~ullman/ialc/spr10/slides/rs2.pdf
slide22 DFA FinFin
slide22 = DFA { delta = δ
, q0 = 0
, fs = singleton 2
} where δ (0, 0) = 1
δ (0, 1) = 2
δ (1, 0) = 0
δ (1, 1) = 2
δ (2, 0) = 0
δ (2, 1) = 1
h Bool [Fin₂]
h False = [0,1]
h True = []
expected DFA FinBool
expected = DFA { delta = δ
, q0 = 0
, fs = singleton 2
} where δ (0, False) = 2
δ (0, True) = 0
δ (1, False) = 2
δ (1, True) = 1
δ (2, False) = 2
δ (2, True) = 2



0 comments on commit 92a0992

Please sign in to comment.