on main help sign in
Add simple tests for TypeRepMap
commit54feff42f41b324c664558cddaf7bd365ddeae81 authorvrom911 <vrom911@gmail.com> dateSat 16 Dec 2017, 15:56 (9 years ago) parenteccca6c
5 files changed+42−61
stack.yaml+3−58 test/Spec.hs−2 test/Test.hs+1 test/Test/TypeRep/Map.hs+33 typerep-map.cabal+5−1
stack.yaml+3−58
@@ -1,66 +1,11 @@
1−# This file was automatically generated by 'stack init'
2−#
3−# Some commonly used options have been documented as comments in this file.
4−# For advanced use and comprehensive documentation of the format, please see:
5−# https://docs.haskellstack.org/en/stable/yaml_configuration/
6−
7−# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8−# A snapshot resolver dictates the compiler version and the set of packages
9−# to be used for project dependencies. For example:
10−#
11−# resolver: lts-3.5
12−# resolver: nightly-2015-09-21
13−# resolver: ghc-7.10.2
14−# resolver: ghcjs-0.1.0_ghc-7.10.2
15−# resolver:
16−# name: custom-snapshot
17−# location: "./custom-snapshot.yaml"
181resolver: lts-9.18
192
20−# User packages to be built.
21−# Various formats can be used as shown in the example below.
22−#
23−# packages:
24−# - some-directory
25−# - https://example.com/foo/bar/baz-0.0.2.tar.gz
26−# - location:
27−# git: https://github.com/commercialhaskell/stack.git
28−# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29−# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30−# extra-dep: true
31−# subdirs:
32−# - auto-update
33−# - wai
34−#
35−# A package marked 'extra-dep: true' will only be built if demanded by a
36−# non-dependency (i.e. a user package), and its test suites and benchmarks
37−# will not be run. This is useful for tweaking upstream packages.
383packages:
394- .
40−# Dependency packages to be pulled from upstream that are not in the resolver
41−# (e.g., acme-missiles-0.3)
42−extra-deps: []
435
44−# Override default flag values for local packages and extra-deps
6+extra-deps:
7+- tasty-discover-4.1.1
8+
459flags: {}
4610
47−# Extra package databases containing global packages
4811extra-package-dbs: []
49−
50−# Control whether we use the GHC we find on the path
51−# system-ghc: true
52−#
53−# Require a specific version of stack, using version ranges
54−# require-stack-version: -any # Default
55−# require-stack-version: ">=1.5"
56−#
57−# Override the architecture used by stack, especially useful on Windows
58−# arch: i386
59−# arch: x86_64
60−#
61−# Extra directories used by stack for building
62−# extra-include-dirs: [/path/to/dir]
63−# extra-lib-dirs: [/path/to/dir]
64−#
65−# Allow a newer minor version of GHC than the snapshot specifies
66−# compiler-check: newer-minor
test/Spec.hsdeleted−2
@@ -1,2 +0,0 @@
1−main :: IO ()
2−main = putStrLn "Test suite not yet implemented"
test/Test.hsnew file+1
@@ -0,0 +1 @@
1+{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --tree-display #-}
test/Test/TypeRep/Map.hsnew file+33
@@ -0,0 +1,33 @@
1+module Test.TypeRep.Map where
2+
3+import Prelude hiding (lookup)
4+
5+import Test.Tasty.Hspec
6+
7+import Data.TypeRep.Map
8+
9+-- Simple test for 'lookup', 'insert' and 'size' functions.
10+spec_insertLookup :: Spec
11+spec_insertLookup = do
12+ describe "Lookup Test" $ do
13+ it "returns the inserted element" $
14+ lookup (insert 'a' empty) `shouldBe` Just 'a'
15+ it "returns the second inserted value of the same type" $
16+ lookup (insert 'b' $ insert 'a' empty) `shouldBe` Just 'b'
17+
18+ describe "Size Test" $ do
19+ it "is empty" $
20+ size empty `shouldBe` 0
21+ it "is of size 1 when 1 element inserted" $
22+ size (insert 'a' empty) `shouldBe` 1
23+ it "doesn't increase size when element of the same type is added" $
24+ size (insert 'b' $ insert 'a' empty) `shouldBe` 1
25+ it "returns 10 when 10 different types are inserted" $
26+ size mapOf10 `shouldBe` 10
27+
28+
29+mapOf10 :: TypeRepMap
30+mapOf10 = insert True $ insert [True, False] $ insert (Just True)
31+ $ insert (Just ()) $ insert [()] $ insert ()
32+ $ insert "aaa" $ insert (Just 'a') $ insert 'a'
33+ $ insert (11 :: Int) empty
typerep-map.cabal+5−1
@@ -25,9 +25,13 @@ library
2525test-suite typerep-map-test
2626 type: exitcode-stdio-1.0
2727 hs-source-dirs: test
28− main-is: Spec.hs
28+ main-is: Test.hs
29+ other-modules: Test.TypeRep.Map
2930 build-depends: base
3031 , typerep-map
32+ , tasty
33+ , tasty-discover >= 4.1.1
34+ , tasty-hspec
3135 ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
3236 default-language: Haskell2010
3337