From 6598ebd3c8d47e004a6f5af8e51dbcd42b6f0dd5 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 11 Dec 2007 17:21:30 +0000 Subject: [PATCH] Added a helper function for the Omega Test tests, and added a further test --- transformations/RainUsageCheckTest.hs | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/transformations/RainUsageCheckTest.hs b/transformations/RainUsageCheckTest.hs index 832f721..8154d70 100644 --- a/transformations/RainUsageCheckTest.hs +++ b/transformations/RainUsageCheckTest.hs @@ -20,6 +20,7 @@ module RainUsageCheckTest (tests) where import Control.Monad.Identity import Data.Graph.Inductive +import Data.Array import qualified Data.Map as Map import qualified Data.Set as Set import Prelude hiding (fail) @@ -299,18 +300,31 @@ testArrayCheck :: Test testArrayCheck = TestList [ -- x_1 = 0 - TestCase $ assertEqual "testArrayCheck 0" (Just []) (solveConstraints [simpleArray [(0,0),(1,1)]] []) - -- x_1 = 0, 3x_1 >= 0 - ,TestCase $ assertEqual "testArrayCheck 0a" (Just [simpleArray [(0,0),(1,0)]]) (solveConstraints [simpleArray [(0,0),(1,1)]] [simpleArray [(0,0),(1,3)]]) - -- x_1 = 7 - ,TestCase $ assertEqual "testArrayCheck 1" (Just []) (solveConstraints [simpleArray [(0,-7),(1,1)]] []) + pass (0, [], [[0,1]], []) + -- x_1 = 0, 3x_1 >= 0 --> 0 >= 0 + ,pass (1, [[0,0]], [[0,1]], [[0,3]]) + -- -7 + x_1 = 0 + ,pass (2, [], [[-7,1]], []) + -- x_1 = 9, 3 + 2x_1 >= 0 --> 21 >= 0 + ,pass (3, [[21,0]], [[-9,1]], [[3,2]]) + + + -- Impossible/inconsistent equality constraints: + -- -7 = 0 - ,TestCase $ assertEqual "testArrayCheck 2" (Nothing) (solveConstraints [simpleArray [(0,7),(1,0)]] []) + ,TestCase $ assertEqual "testArrayCheck 1002" (Nothing) (solveConstraints [simpleArray [(0,7),(1,0)]] []) -- x_1 = 3, x_1 = 4 - ,TestCase $ assertEqual "testArrayCheck 3" (Nothing) (solveConstraints [simpleArray [(0,-3),(1,1)], simpleArray [(0,-4),(1,1)]] []) + ,TestCase $ assertEqual "testArrayCheck 1003" (Nothing) (solveConstraints [simpleArray [(0,-3),(1,1)], simpleArray [(0,-4),(1,1)]] []) -- x_1 + x_2 = 0, x_1 + x_2 = -3 - ,TestCase $ assertEqual "testArrayCheck 4" (Nothing) (solveConstraints [simpleArray [(0,0),(1,1),(2,1)], simpleArray [(0,3),(1,1),(2,1)]] []) + ,TestCase $ assertEqual "testArrayCheck 1004" (Nothing) (solveConstraints [simpleArray [(0,0),(1,1),(2,1)], simpleArray [(0,3),(1,1),(2,1)]] []) ] + where + pass :: (Int, [[Integer]], [[Integer]], [[Integer]]) -> Test + pass (ind, expIneq, inpEq, inpIneq) = TestCase $ assertEqual ("testArrayCheck " ++ show ind) + (Just $ arrayise expIneq) (solveConstraints (arrayise inpEq) (arrayise inpIneq)) + + arrayise :: [[Integer]] -> [Array Int Integer] + arrayise = map (simpleArray . zip [0..]) tests :: Test