-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_test.go
More file actions
28 lines (23 loc) · 761 Bytes
/
example_test.go
File metadata and controls
28 lines (23 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package dauction_test
import (
"fmt"
"github.com/kchristidis/dauction"
)
func ExampleSettle() {
// group buyer bids into a bid collection object
bb1 := dauction.Bid{PricePerUnit: 8, Units: 2}
bb2 := dauction.Bid{PricePerUnit: 10, Units: 2}
buyerBids := dauction.BidCollection{bb1, bb2}
// same for seller bids
sb1 := dauction.Bid{PricePerUnit: 6, Units: 1}
sb2 := dauction.Bid{PricePerUnit: 9, Units: 1}
sellerBids := dauction.BidCollection{sb1, sb2}
// have the auctioneer clear the market
res, err := dauction.Settle(buyerBids, sellerBids)
if err != nil { // when no clearing price can be found
fmt.Println(err)
}
// - res.PricePerUnit = 9.5 (clearing price)
// - res.Units = 2 (number of units that can be cleared)
fmt.Println(res)
}