@@ -26,7 +26,8 @@ import Data.Word (Word64)
26
26
import Formatting (bprint , build , formatToString , (%) )
27
27
import qualified Formatting.Buildable
28
28
import Serokell.Util (listJson )
29
- import Test.QuickCheck (Arbitrary (.. ), arbitrary , elements , suchThat )
29
+ import Test.QuickCheck (Arbitrary (.. ), arbitrary , choose , elements ,
30
+ infiniteListOf , shuffle )
30
31
31
32
import Cardano.Wallet.API.V1.Swagger.Example (Example )
32
33
import Pos.Infra.Util.LogSafe (BuildableSafeGen (.. ),
@@ -59,9 +60,9 @@ generateBounds bType =
59
60
60
61
instance Arbitrary HistogramBar where
61
62
arbitrary = do
62
- possiblenames <- elements (NL. toList $ generateBounds Log10 )
63
- bound <- arbitrary `suchThat` ( >= 0 )
64
- pure (HistogramBarCount possiblenames bound )
63
+ upperBound <- elements (NL. toList $ generateBounds Log10 )
64
+ count <- arbitrary
65
+ pure (HistogramBarCount upperBound count )
65
66
66
67
67
68
deriveSafeBuildable ''HistogramBar
@@ -112,11 +113,11 @@ eitherToParser :: Buildable a => Either a b -> Parser b
112
113
eitherToParser =
113
114
either (fail . formatToString build) pure
114
115
115
- toMap :: [HistogramBar ] -> Map Word64 Word64
116
- toMap = Map. fromList . map (\ (HistogramBarCount key val ) -> ( key,val) )
116
+ sorted :: [HistogramBar ] -> [ HistogramBar ]
117
+ sorted = sortOn (\ (HistogramBarCount key _ ) -> key)
117
118
118
119
instance Eq UtxoStatistics where
119
- (UtxoStatistics h s) == (UtxoStatistics h' s') = s == s' && toMap h == toMap h'
120
+ (UtxoStatistics h s) == (UtxoStatistics h' s') = s == s' && sorted h == sorted h'
120
121
121
122
instance ToJSON UtxoStatistics where
122
123
toJSON (UtxoStatistics bars allStakes) =
@@ -206,16 +207,14 @@ instance ToSchema UtxoStatistics where
206
207
)
207
208
208
209
instance Arbitrary UtxoStatistics where
209
- arbitrary = UtxoStatistics <$> arbitrary
210
- <*> arbitrary
211
- -- This code goes into nonstoping computation when checking swagger integration of WalletResponse UtxoStatistics
212
- {- - do
213
- histogram <- arbitrary
214
- let (minPossibleValue, maxPossibleValue) = getPossibleBounds histogram
215
- let histoBars = map (uncurry HistogramBarCount) $ Map.toList histogram
216
- allStakes <- arbitrary `suchThat` (\s -> s >= minPossibleValue && s <= maxPossibleValue)
210
+ arbitrary = do
211
+ upperBounds <- shuffle (NL. toList $ generateBounds Log10 )
212
+ counts <- infiniteListOf arbitrary
213
+ let histogram = zip upperBounds counts
214
+ let histoBars = map (uncurry HistogramBarCount ) histogram
215
+ allStakes <- choose (getPossibleBounds $ Map. fromList histogram)
217
216
return $ UtxoStatistics histoBars allStakes
218
- - -}
217
+
219
218
instance Buildable [HistogramBar ] where
220
219
build =
221
220
bprint listJson
0 commit comments