locators 0.2.4.2 → 0.2.4.3
raw patch · 8 files changed
+145/−19 lines, 8 filesdep +locatorssetup-changed
Dependencies added: locators
Files
- LICENCE +32/−0
- Setup.hs +0/−2
- locators.cabal +18/−13
- src/Data/Locator.hs +1/−1
- src/Data/Locator/Hashes.hs +1/−1
- src/Data/Locator/Locators.hs +1/−1
- tests/TestSuite.hs +91/−0
- tests/check.hs +1/−1
+ LICENCE view
@@ -0,0 +1,32 @@+Human exchangable identifiers and locators++Copyright © 2013-2018 Operational Dynamics Consulting, Pty Ltd+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++ 1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ 2. Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.+ + 3. Neither the name of the project nor the names of its contributors+ may be used to endorse or promote products derived from this + software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
locators.cabal view
@@ -1,13 +1,21 @@ cabal-version: >= 1.10 name: locators-version: 0.2.4.2+version: 0.2.4.3 synopsis: Human exchangable identifiers and locators license: BSD3+license-file: LICENCE+description: + /Overview/+ .+ Simple identifiers (as used, for example, as "locators" in airline reservation+ systems) using a subset of the Latin1 alphabet whose characters are unambigious+ when written or spoken.+ author: Andrew Cowie <andrew@operationaldynamics.com> maintainer: Andrew Cowie <andrew@operationaldynamics.com>-copyright: © 2013-2014 Operational Dynamics Consulting, Pty Ltd and Others+copyright: © 2013-2018 Operational Dynamics Consulting, Pty Ltd and Others category: Other-tested-with: GHC == 7.6+tested-with: GHC == 8.2 stability: experimental build-type: Simple@@ -29,16 +37,14 @@ Data.Locator.Locators - ghc-options: -O2- -threaded- -Wall+ ghc-options: -Wall -Wwarn -fwarn-tabs -funbox-strict-fields -fno-warn-missing-signatures -fno-warn-unused-do-bind - ghc-prof-options: -prof -fprof-auto-top+ ghc-prof-options: -fprof-auto-exported test-suite check@@ -54,13 +60,14 @@ bytestring, containers, cryptohash,- cereal+ cereal,+ locators - hs-source-dirs: src,tests+ hs-source-dirs: tests main-is: check.hs+ other-modules: TestSuite - ghc-options: -O2- -threaded+ ghc-options: -threaded -Wall -Wwarn -fwarn-tabs@@ -69,8 +76,6 @@ -fno-warn-unused-do-bind include-dirs: .-- ghc-prof-options: -prof -fprof-auto-top source-repository head
src/Data/Locator.hs view
@@ -1,7 +1,7 @@ -- -- Human exchangable identifiers and locators ----- Copyright © 2011-2014 Operational Dynamics Consulting, Pty Ltd+-- Copyright © 2011-2017 Operational Dynamics Consulting, Pty Ltd -- -- The code in this file, and the program it is a part of, is -- made available to you by its authors as open source software:
src/Data/Locator/Hashes.hs view
@@ -1,7 +1,7 @@ -- -- Human exchangable identifiers and locators ----- Copyright © 2011-2014 Operational Dynamics Consulting, Pty Ltd+-- Copyright © 2011-2017 Operational Dynamics Consulting, Pty Ltd -- -- The code in this file, and the program it is a part of, is -- made available to you by its authors as open source software:
src/Data/Locator/Locators.hs view
@@ -1,7 +1,7 @@ -- -- Human exchangable identifiers and locators ----- Copyright © 2011-2014 Operational Dynamics Consulting, Pty Ltd+-- Copyright © 2011-2017 Operational Dynamics Consulting, Pty Ltd -- -- The code in this file, and the program it is a part of, is -- made available to you by its authors as open source software:
+ tests/TestSuite.hs view
@@ -0,0 +1,91 @@+--+-- Human exchangable identifiers and locators+--+-- Copyright © 2013-2017 Operational Dynamics Consulting, Pty Ltd+--+-- The code in this file, and the program it is a part of, is+-- made available to you by its authors as open source software:+-- you can redistribute it and/or modify it under the terms of+-- the BSD licence.+--++{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS -fno-warn-unused-imports #-}+{-# OPTIONS -fno-warn-orphans #-}+{-# OPTIONS -fno-warn-type-defaults #-}+{-# OPTIONS -fno-warn-missing-signatures #-}++module TestSuite where++import Test.Hspec+import Test.Hspec.QuickCheck+import Test.HUnit+import Test.QuickCheck (elements, property)+import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)+++--+-- Otherwise redundent imports, but useful for testing in GHCi.+--++import Data.ByteString (ByteString)+import qualified Data.ByteString as B+import qualified Data.ByteString.Char8 as S+import qualified Data.Map.Strict as Map+import Debug.Trace++--+-- What we're actually testing.+--++import Data.Locator++suite :: Spec+suite = do+ describe "Locators" $ do+ testRoundTripLocator16+ testKnownLocator16a+ testProblematicEdgeCases+ testNegativeNumbers++ describe "Hashes" $ do+ testPaddingRefactored+++testRoundTripLocator16 =+ prop "safe conversion to/from Locator16" prop_Locator16++prop_Locator16 :: Int -> Bool+prop_Locator16 i =+ let+ n = abs i+ decoded = fromLocator16 (toLocator16 n)+ in+ n == decoded+++--+-- Have to do these manually, since Locator16a is not round-trip safe.+--+testKnownLocator16a =+ it "constrains Locator16a to unique digits" $ do+ assertEqual "Incorrect result" "12C4FH" (toLocator16a 6 0x111111)+ assertEqual "Incorrect result" "789KLM" (toLocator16a 6 0x777777)+ assertEqual "Incorrect result" "MRXY01" (toLocator16a 6 0xCCCCCC)++testProblematicEdgeCases =+ it "converstion to Locator16a correct on corner cases" $ do+ assertEqual "Incorrect result" "012C4F" (toLocator16a 6 0x0)+ assertEqual "Incorrect result" "FHL417" (hashStringToLocator16a 6 "perf_data")+ assertEqual "Incorrect result" "K48F01" (hashStringToLocator16a 6 "perf_data/bletchley")++testPaddingRefactored =+ it "correctly pads strings" $ do+ assertEqual "Incorrect result" "00001" (padWithZeros 5 "1")+ assertEqual "Incorrect result" "123456" (padWithZeros 5 "123456")+ assertEqual "Incorrect result" "LygHa16AHYG" (padWithZeros 11 . toBase62 $ 2^64)+ assertEqual "Incorrect result" "k8SQgkJtxLo" (hashStringToBase62 11 . S.pack . show $ 2^64)++testNegativeNumbers =+ it "doesn't explode if fed a negative number" $ do+ assertEqual "Incorrect outcome" "1" (toLocator16a 1 (-1))
tests/check.hs view
@@ -1,7 +1,7 @@ -- -- Human exchangable identifiers and locators ----- Copyright © 2013-2014 Operational Dynamics Consulting, Pty Ltd+-- Copyright © 2013-2017 Operational Dynamics Consulting, Pty Ltd -- -- The code in this file, and the program it is a part of, is -- made available to you by its authors as open source software: