diff options
| author | manuel <manuel@mausz.at> | 2012-05-22 00:21:05 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-05-22 00:21:05 +0200 |
| commit | 85ac51660b298681ba3dcaee9def5f1e5f2c5284 (patch) | |
| tree | 626eadd34b8b63b8decab85bdd90feaa9e939bdb | |
| parent | 2e27b9c40e78da4acfc659ca096b4fced68f3cc6 (diff) | |
| download | ffp-85ac51660b298681ba3dcaee9def5f1e5f2c5284.tar.gz ffp-85ac51660b298681ba3dcaee9def5f1e5f2c5284.tar.bz2 ffp-85ac51660b298681ba3dcaee9def5f1e5f2c5284.zip | |
adding test and some minor fixes
| -rw-r--r-- | AufgabeFFP7.hs | 8 | ||||
| -rwxr-xr-x | TestAufgabeFFP7.hs | 66 |
2 files changed, 64 insertions, 10 deletions
diff --git a/AufgabeFFP7.hs b/AufgabeFFP7.hs index c9454a5..091cb49 100644 --- a/AufgabeFFP7.hs +++ b/AufgabeFFP7.hs | |||
| @@ -13,7 +13,7 @@ empty = (0, "") | |||
| 13 | 13 | ||
| 14 | -- insert character before cursor | 14 | -- insert character before cursor |
| 15 | insert :: Char -> Buffer -> Buffer | 15 | insert :: Char -> Buffer -> Buffer |
| 16 | insert c (cur, buf) = (cur, buf1 ++ [c] ++ buf2) | 16 | insert c (cur, buf) = (min (length buf + 1) (max (cur - 1) 0), buf1 ++ [c] ++ buf2) |
| 17 | where | 17 | where |
| 18 | (buf1, buf2) = splitAt cur buf | 18 | (buf1, buf2) = splitAt cur buf |
| 19 | 19 | ||
| @@ -21,7 +21,7 @@ insert c (cur, buf) = (cur, buf1 ++ [c] ++ buf2) | |||
| 21 | delete :: Buffer -> Buffer | 21 | delete :: Buffer -> Buffer |
| 22 | delete (cur, buf) | 22 | delete (cur, buf) |
| 23 | | buf2 == [] = (min cur (length buf1), buf1) | 23 | | buf2 == [] = (min cur (length buf1), buf1) |
| 24 | | cur < 0 = (cur, buf) | 24 | | cur < 0 = (0, buf) |
| 25 | | otherwise = (cur, buf1 ++ tail buf2) | 25 | | otherwise = (cur, buf1 ++ tail buf2) |
| 26 | where | 26 | where |
| 27 | (buf1, buf2) = splitAt cur buf | 27 | (buf1, buf2) = splitAt cur buf |
| @@ -36,11 +36,11 @@ right (cur, buf) = (max 0 (min (cur + 1) (length buf)), buf) | |||
| 36 | 36 | ||
| 37 | -- is cursor at left end? | 37 | -- is cursor at left end? |
| 38 | atLeft :: Buffer -> Bool | 38 | atLeft :: Buffer -> Bool |
| 39 | atLeft (cur, buf) = cur == 0 | 39 | atLeft (cur, buf) = cur <= 0 |
| 40 | 40 | ||
| 41 | -- is cursor at right end? | 41 | -- is cursor at right end? |
| 42 | atRight :: Buffer -> Bool | 42 | atRight :: Buffer -> Bool |
| 43 | atRight (cur, buf) = cur == length buf | 43 | atRight (cur, buf) = cur >= length buf |
| 44 | 44 | ||
| 45 | -------------------------------------------------------------------------------- | 45 | -------------------------------------------------------------------------------- |
| 46 | 46 | ||
diff --git a/TestAufgabeFFP7.hs b/TestAufgabeFFP7.hs index f83952b..16952cb 100755 --- a/TestAufgabeFFP7.hs +++ b/TestAufgabeFFP7.hs | |||
| @@ -9,12 +9,66 @@ import AufgabeFFP7 | |||
| 9 | import Test.QuickCheck | 9 | import Test.QuickCheck |
| 10 | import System.IO.Unsafe | 10 | import System.IO.Unsafe |
| 11 | 11 | ||
| 12 | {-- | 12 | cases1 = TestLabel "buffer" $ TestList [ |
| 13 | cases1 = TestLabel "TODO" $ TestList [ | 13 | TestCase $ assertEqual "empty" (0, "") |
| 14 | TestCase $ assertEqual "TODO" (result) (call) | 14 | (empty), |
| 15 | ... | 15 | |
| 16 | TestCase $ assertEqual "insert1" (0, "a") | ||
| 17 | (insert 'a' empty), | ||
| 18 | TestCase $ assertEqual "insert2" (0, "ba") | ||
| 19 | (insert 'b' (insert 'a' empty)), | ||
| 20 | TestCase $ assertEqual "insert3" (0, "ba") | ||
| 21 | (insert 'b' (insert 'a' empty)), | ||
| 22 | TestCase $ assertEqual "insert4" (0, "ba") | ||
| 23 | (insert 'b' (-100, "a")), | ||
| 24 | TestCase $ assertEqual "insert5" (2, "ab") | ||
| 25 | (insert 'b' (100, "a")), | ||
| 26 | |||
| 27 | TestCase $ assertEqual "delete1" (0, "bc") | ||
| 28 | (delete (0, "abc")), | ||
| 29 | TestCase $ assertEqual "delete2" (2, "ab") | ||
| 30 | (delete (2, "abc")), | ||
| 31 | TestCase $ assertEqual "delete3" (0, "abc") | ||
| 32 | (delete (-100, "abc")), | ||
| 33 | TestCase $ assertEqual "delete4" (3, "abc") | ||
| 34 | (delete (100, "abc")), | ||
| 35 | |||
| 36 | TestCase $ assertEqual "left1" (0, "abc") | ||
| 37 | (left (0, "abc")), | ||
| 38 | TestCase $ assertEqual "left2" (0, "abc") | ||
| 39 | (left (-100, "abc")), | ||
| 40 | TestCase $ assertEqual "left3" (1, "abc") | ||
| 41 | (left (2, "abc")), | ||
| 42 | TestCase $ assertEqual "left4" (3, "abc") | ||
| 43 | (left (4, "abc")), | ||
| 44 | TestCase $ assertEqual "left5" (3, "abc") | ||
| 45 | (left (100, "abc")), | ||
| 46 | |||
| 47 | TestCase $ assertEqual "right1" (1, "abc") | ||
| 48 | (right (0, "abc")), | ||
| 49 | TestCase $ assertEqual "right2" (0, "abc") | ||
| 50 | (right (-100, "abc")), | ||
| 51 | TestCase $ assertEqual "right3" (2, "abc") | ||
| 52 | (right (1, "abc")), | ||
| 53 | TestCase $ assertEqual "right4" (3, "abc") | ||
| 54 | (right (3, "abc")), | ||
| 55 | TestCase $ assertEqual "right5" (3, "abc") | ||
| 56 | (right (100, "abc")), | ||
| 57 | |||
| 58 | TestCase $ assertEqual "atLeft1" (True) | ||
| 59 | (atLeft (0, "abc")), | ||
| 60 | TestCase $ assertEqual "atLeft2" (False) | ||
| 61 | (atLeft (1, "abc")), | ||
| 62 | TestCase $ assertEqual "atLeft3" (True) | ||
| 63 | (atLeft (-100, "abc")), | ||
| 64 | |||
| 65 | TestCase $ assertEqual "atRight1" (True) | ||
| 66 | (atRight (3, "abc")), | ||
| 67 | TestCase $ assertEqual "atRight2" (False) | ||
| 68 | (atRight (1, "abc")), | ||
| 69 | TestCase $ assertEqual "atRight3" (True) | ||
| 70 | (atRight (100, "abc")) | ||
| 16 | ] | 71 | ] |
| 17 | --} | ||
| 18 | 72 | ||
| 19 | -------------------------------------------------------------------------------- | 73 | -------------------------------------------------------------------------------- |
| 20 | 74 | ||
| @@ -35,7 +89,7 @@ cases2 = TestLabel "ssfn/minfree" $ TestList [ | |||
| 35 | -------------------------------------------------------------------------------- | 89 | -------------------------------------------------------------------------------- |
| 36 | 90 | ||
| 37 | tests :: [Test] | 91 | tests :: [Test] |
| 38 | tests = [cases2] | 92 | tests = [cases1, cases2] |
| 39 | 93 | ||
| 40 | isSuccess :: Counts -> Bool | 94 | isSuccess :: Counts -> Bool |
| 41 | isSuccess Counts{ cases = _, tried = _, errors = 0, failures = 0 } = True | 95 | isSuccess Counts{ cases = _, tried = _, errors = 0, failures = 0 } = True |
