1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE OverloadedStrings #-}
4module Test.ApproxEq where
6import Database.Bloodhound
10import qualified Data.List.NonEmpty as NE
12-- | Typeclass for "equal where it matters". Use this to specify
13-- less-strict equivalence for things such as lists that can wind up
14-- in an unpredictable order
16 (=~) :: a -> a -> Bool
18 showApproxEq :: a -> String
19 default showApproxEq :: (Show a) => a -> String
22(==~) :: (ApproxEq a) => a -> a -> Property
23a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
25instance ApproxEq NominalDiffTime where (=~) = (==)
26instance ApproxEq Bool where (=~) = (==)
27instance ApproxEq Int where (=~) = (==)
28instance (Eq a, Show a) => ApproxEq (Maybe a) where (=~) = (==)
29instance ApproxEq Char where
32instance ApproxEq NodeAttrFilter where (=~) = (==)
33instance ApproxEq NodeAttrName where (=~) = (==)
34instance (Eq a, Show a) => ApproxEq (NonEmpty a) where (=~) = (==)
35instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
36 Left a =~ Left b = a =~ b
37 Right a =~ Right b = a =~ b
39 showApproxEq (Left x) = "Left " <> showApproxEq x
40 showApproxEq (Right x) = "Right " <> showApproxEq x
41instance (ApproxEq a, Show a) => ApproxEq [a] where
42 as =~ bs = and (zipWith (=~) as bs)
43instance ApproxEq ReplicaCount where (=~) = (==)
44instance ApproxEq ReplicaBounds where (=~) = (==)
45instance ApproxEq Bytes where (=~) = (==)
46instance ApproxEq AllocationPolicy where (=~) = (==)
47instance ApproxEq InitialShardCount where (=~) = (==)
48instance ApproxEq FSType where (=~) = (==)
50-- | Due to the way nodeattrfilters get serialized here, they may come
51-- out in a different order, but they are morally equivalent
52instance ApproxEq UpdatableIndexSetting where
53 RoutingAllocationInclude a =~ RoutingAllocationInclude b =
54 NE.sort a =~ NE.sort b
55 RoutingAllocationExclude a =~ RoutingAllocationExclude b =
56 NE.sort a =~ NE.sort b
57 RoutingAllocationRequire a =~ RoutingAllocationRequire b =
58 NE.sort a =~ NE.sort b
60 showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
61 showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
62 showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
63 showApproxEq x = show x
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list