Created
March 4, 2020 10:51
-
-
Save thiagolioy/23b083e9f7f2b8d051587f67919a6981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testShouldCalculatePaymentDistributionMoreComplicatedEventMohaLair() { | |
let moha = Player(name: "Moha") | |
let kaique = Player(name: "Kaique") | |
let lioy = Player(name: "Lioy") | |
let jonas = Player(name: "Jonas") | |
let lima = Player(name: "Lima") | |
let igarashi = Player(name: "Igarashi") | |
let saba = Player(name: "Saba") | |
let paiLima = Player(name: "PaiLima") | |
let players = [moha, kaique, lioy, jonas, lima, igarashi, saba, paiLima] | |
let playerActions = [ | |
PlayerAction(player: moha, action: .buyIn), | |
PlayerAction(player: moha, action: .rebuy), | |
PlayerAction(player: moha, action: .rebuy), | |
PlayerAction(player: moha, action: .addOn), | |
PlayerAction(player: kaique, action: .buyIn), | |
PlayerAction(player: kaique, action: .rebuy), | |
PlayerAction(player: kaique, action: .rebuy), | |
PlayerAction(player: kaique, action: .addOn), | |
PlayerAction(player: lioy, action: .buyIn), | |
PlayerAction(player: lioy, action: .rebuy), | |
PlayerAction(player: lioy, action: .addOn), | |
PlayerAction(player: jonas, action: .buyIn), | |
PlayerAction(player: jonas, action: .addOn), | |
PlayerAction(player: lima, action: .buyIn), | |
PlayerAction(player: lima, action: .addOn), | |
PlayerAction(player: igarashi, action: .buyIn), | |
PlayerAction(player: igarashi, action: .rebuy), | |
PlayerAction(player: igarashi, action: .rebuy), | |
PlayerAction(player: igarashi, action: .rebuy), | |
PlayerAction(player: igarashi, action: .addOn), | |
PlayerAction(player: saba, action: .buyIn), | |
PlayerAction(player: saba, action: .rebuy), | |
PlayerAction(player: saba, action: .rebuy), | |
PlayerAction(player: saba, action: .rebuy), | |
PlayerAction(player: saba, action: .rebuy), | |
PlayerAction(player: saba, action: .addOn), | |
PlayerAction(player: paiLima, action: .buyIn), | |
PlayerAction(player: paiLima, action: .rebuy), | |
PlayerAction(player: paiLima, action: .rebuy), | |
PlayerAction(player: paiLima, action: .rebuy), | |
PlayerAction(player: paiLima, action: .addOn), | |
] | |
let loc = Location(address: "Casa Moha", complement: "80") | |
var ev = Event( | |
name: "Etapa 2 - Moha Lair", | |
location: loc, | |
date: Date(), | |
players: players.map{EventPlayer(player: $0)}, | |
actions: playerActions | |
) | |
let store = EventStore() | |
ev = store.playerDidLose(player: lima, on: ev) | |
ev = store.playerDidLose(player: moha, on: ev) | |
ev = store.playerDidLose(player: paiLima, on: ev) | |
ev = store.playerDidLose(player: igarashi, on: ev) | |
ev = store.playerDidLose(player: kaique, on: ev) | |
ev = store.playerDidLose(player: jonas, on: ev) | |
ev = store.playerDidLose(player: lioy, on: ev) | |
let dist = PaymentDistribuition() | |
let transfers = dist.calculate(for: ev) | |
XCTAssertEqual(transfers.count, 7) | |
let expectedTransfers = [ | |
Transaction(from: paiLima, to: saba, amount: 250), | |
Transaction(from: igarashi, to: saba, amount: 250), | |
Transaction(from: moha, to: saba, amount: 200), | |
Transaction(from: kaique, to: saba, amount: 85), | |
Transaction(from: kaique, to: lioy, amount: 115), | |
Transaction(from: lima, to: lioy, amount: 100), | |
Transaction(from: jonas, to: lioy, amount: 100) | |
] | |
XCTAssertEqual(transfers, expectedTransfers) | |
let transferTotal = transfers.map({$0.amount}).reduce(0, +) | |
XCTAssertEqual(transferTotal, 1100) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment