Add tests for auction winner determination algorithm.
[?]
Mar 5, 2016, 4:26 PM
HBULCDN6E75FAPILFVLTQIKABDEWL3HZTBLICLCWOIKDRYM6UIBQCDependencies
- [2]
M4KM76DGMerge branch 'stackify' - [3]
F2XLL7XWRemove Ord Bid & sort in favor of sortBy - [4]
GLFF5ZDKFactor winningBids for easier testing. - [5]
ZP62WC47Begin conversion to build with stack. - [6]
WO2MINIFAuctions now compile! - [7]
IZEVQF62Work in progress replacing sqlite with postgres. - [8]
LAROLAYUWIP - [9]
7HPY3QPFFix linting errors. (yay hlint!) - [10]
75N3UJ4JMore progression toward lenses. - [11]
KEP5WUFJConvert project to stack-based build. - [12]
NEDDHXUKReformat via stylish-haskell - [13]
2XQD6KKKAdd invitation logic and clean up DBProg error handling. - [14]
UUR6SMCAAdd start of specs for auctions. - [15]
TLQ72DSJLenses, sqlite-simple
Change contents
- edit in lib/Aftok/Auction.hs at line 9
import Data.Thyme.Format () - replacement in lib/Aftok/Auction.hs at line 32[5.192]→[5.106:122](∅→∅),[5.257]→[5.106:122](∅→∅),[5.1706]→[5.106:122](∅→∅),[5.5400]→[5.106:122](∅→∅)
} deriving Eq} deriving (Eq, Show) - replacement in lib/Aftok/Auction.hs at line 37
comparing costRatiocomparing costRatio `mappend` comparing (^. bidTime) - replacement in lib/Aftok/Auction.hs at line 50
takeWinningBids total (x : xs)takeWinningBids total (bid : xs) - replacement in lib/Aftok/Auction.hs at line 52
| total + (x ^. bidAmount) < raiseAmount' =x : takeWinningBids (total + (x ^. bidAmount)) xs| total + (bid ^. bidAmount) < raiseAmount' =bid : takeWinningBids (total + (bid ^. bidAmount)) xs - replacement in lib/Aftok/Auction.hs at line 58[4.275]→[5.375:454](∅→∅),[5.333]→[5.375:454](∅→∅),[5.454]→[2.55:55](∅→∅),[2.55]→[5.64:158](∅→∅),[5.454]→[5.64:158](∅→∅),[5.454]→[5.64:158](∅→∅),[5.403]→[5.64:158](∅→∅)
winFraction = toRational remainder / toRational (x ^. bidAmount)remainderSeconds = Seconds . round $ winFraction * toRational (x ^. bidSeconds)winFraction = toRational remainder / toRational (bid ^. bidAmount)remainderSeconds = Seconds . round $ winFraction * toRational (bid ^. bidSeconds) - replacement in lib/Aftok/Auction.hs at line 61
in [x & bidSeconds .~ remainderSeconds & bidAmount .~ remainder]in [bid & bidSeconds .~ remainderSeconds & bidAmount .~ remainder] - edit in test/Aftok/AuctionSpec.hs at line 9
import Control.Lens - edit in test/Aftok/AuctionSpec.hs at line 12
--import Data.Thyme.Clock as C - edit in test/Aftok/AuctionSpec.hs at line 14
import Text.Read (read) - replacement in test/Aftok/AuctionSpec.hs at line 17
import Test.QuickCheck--import Test.QuickCheck - replacement in test/Aftok/AuctionSpec.hs at line 20
spec = dodescribe "bid ordering" $it "ensures that bids with lowest seconds/btc ratio are first" $let testB1 = Bid (UserId nil) (Seconds 60) (Satoshi 1000) undefinedtestB2 = Bid (UserId nil) (Seconds 60) (Satoshi 100) undefinedtestB3 = Bid (UserId nil) (Seconds 90) (Satoshi 100) undefinedin dospec =let testB0 = Bid (UserId nil) (Seconds 3) (Satoshi 100) (read "2016-03-05 15:59:26.033176 UTC")testB1 = Bid (UserId nil) (Seconds 60) (Satoshi 1000)(read "2016-03-05 15:59:26.033177 UTC")testB2 = Bid (UserId nil) (Seconds 60) (Satoshi 100) (read "2016-03-05 15:59:26.033178 UTC")testB3 = Bid (UserId nil) (Seconds 90) (Satoshi 100) (read "2016-03-05 15:59:26.033179 UTC")testB4 = Bid (UserId nil) (Seconds 60) (Satoshi 100) (read "2016-03-05 15:59:26.033180 UTC")in dodescribe "bid ordering" $ doit "ensures that bids with lowest seconds/btc ratio are first" $ dobidOrder testB0 testB1 `shouldBe` LT - edit in test/Aftok/AuctionSpec.hs at line 32
it "ensures breaks ties in bid ordering by timestamp" $ dobidOrder testB2 testB4 `shouldBe` LT - replacement in test/Aftok/AuctionSpec.hs at line 36
describe "winning bids" $it "determines a sufficient number of winners to fulfill the raise amount" $True `shouldBe` Truedescribe "winning bids" $ doit "determines a sufficient number of winners to fulfill the raise amount" $let winners = winningBids' (Satoshi 1250) [testB0, testB1, testB2, testB3, testB4]split = Bid (UserId nil) (Seconds 30) (Satoshi 50) (testB4 ^. bidTime)in sortBy bidOrder winners `shouldBe` sortBy bidOrder [testB0, testB1, testB2, split]