Add tests for auction winner determination algorithm.

[?]
Mar 5, 2016, 4:26 PM
HBULCDN6E75FAPILFVLTQIKABDEWL3HZTBLICLCWOIKDRYM6UIBQC

Dependencies

  • [2] M4KM76DG Merge branch 'stackify'
  • [3] F2XLL7XW Remove Ord Bid & sort in favor of sortBy
  • [4] GLFF5ZDK Factor winningBids for easier testing.
  • [5] ZP62WC47 Begin conversion to build with stack.
  • [6] WO2MINIF Auctions now compile!
  • [7] IZEVQF62 Work in progress replacing sqlite with postgres.
  • [8] LAROLAYU WIP
  • [9] 7HPY3QPF Fix linting errors. (yay hlint!)
  • [10] 75N3UJ4J More progression toward lenses.
  • [11] KEP5WUFJ Convert project to stack-based build.
  • [12] NEDDHXUK Reformat via stylish-haskell
  • [13] 2XQD6KKK Add invitation logic and clean up DBProg error handling.
  • [14] UUR6SMCA Add start of specs for auctions.
  • [15] TLQ72DSJ Lenses, sqlite-simple

Change contents

  • edit in lib/Aftok/Auction.hs at line 9
    [5.135]
    [5.135]
    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
    [5.1706]
    [5.258]
    } deriving (Eq, Show)
  • replacement in lib/Aftok/Auction.hs at line 37
    [3.49][3.49:71]()
    comparing costRatio
    [3.49]
    [3.71]
    comparing costRatio `mappend` comparing (^. bidTime)
  • replacement in lib/Aftok/Auction.hs at line 50
    [5.374][5.444:481](),[5.374][5.444:481](),[5.444][5.444:481]()
    takeWinningBids total (x : xs)
    [5.374]
    [5.481]
    takeWinningBids total (bid : xs)
  • replacement in lib/Aftok/Auction.hs at line 52
    [5.538][4.142:194](),[4.194][5.3:63](),[5.390][5.3:63](),[5.165][5.3:63]()
    | total + (x ^. bidAmount) < raiseAmount' =
    x : takeWinningBids (total + (x ^. bidAmount)) xs
    [5.538]
    [5.652]
    | 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)
    [4.275]
    [5.925]
    winFraction = toRational remainder / toRational (bid ^. bidAmount)
    remainderSeconds = Seconds . round $ winFraction * toRational (bid ^. bidSeconds)
  • replacement in lib/Aftok/Auction.hs at line 61
    [5.926][5.678:754]()
    in [x & bidSeconds .~ remainderSeconds & bidAmount .~ remainder]
    [5.926]
    [5.1080]
    in [bid & bidSeconds .~ remainderSeconds & bidAmount .~ remainder]
  • edit in test/Aftok/AuctionSpec.hs at line 9
    [5.277]
    [5.277]
    import Control.Lens
  • edit in test/Aftok/AuctionSpec.hs at line 12
    [5.309]
    [5.309]
    --import Data.Thyme.Clock as C
  • edit in test/Aftok/AuctionSpec.hs at line 14
    [5.336]
    [5.336]
    import Text.Read (read)
  • replacement in test/Aftok/AuctionSpec.hs at line 17
    [5.365][5.365:398]()
    import Test.QuickCheck
    [5.365]
    [5.398]
    --import Test.QuickCheck
  • replacement in test/Aftok/AuctionSpec.hs at line 20
    [5.412][4.279:289](),[4.289][5.419:749](),[5.419][5.419:749]()
    spec = do
    describe "bid ordering" $
    it "ensures that bids with lowest seconds/btc ratio are first" $
    let testB1 = Bid (UserId nil) (Seconds 60) (Satoshi 1000) undefined
    testB2 = Bid (UserId nil) (Seconds 60) (Satoshi 100) undefined
    testB3 = Bid (UserId nil) (Seconds 90) (Satoshi 100) undefined
    in do
    [5.412]
    [5.749]
    spec =
    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 do
    describe "bid ordering" $ do
    it "ensures that bids with lowest seconds/btc ratio are first" $ do
    bidOrder testB0 testB1 `shouldBe` LT
  • edit in test/Aftok/AuctionSpec.hs at line 32
    [5.839]
    [4.290]
    it "ensures breaks ties in bid ordering by timestamp" $ do
    bidOrder testB2 testB4 `shouldBe` LT
  • replacement in test/Aftok/AuctionSpec.hs at line 36
    [4.291][4.291:428]()
    describe "winning bids" $
    it "determines a sufficient number of winners to fulfill the raise amount" $
    True `shouldBe` True
    [4.291]
    [5.839]
    describe "winning bids" $ do
    it "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]