-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dymbe/AI_profit
Ai profit
- Loading branch information
Showing
29 changed files
with
99,824 additions
and
200,120 deletions.
There are no files selected for viewing
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
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
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
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
54 changes: 54 additions & 0 deletions
54
common/src/test/java/nl/tudelft/trustchain/common/MarketCommunityTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package nl.tudelft.trustchain.common | ||
|
||
import io.mockk.* | ||
import nl.tudelft.ipv8.Peer | ||
import nl.tudelft.ipv8.messaging.EndpointAggregator | ||
import nl.tudelft.ipv8.messaging.Serializable | ||
import nl.tudelft.trustchain.common.messaging.TradePayload | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class MarketCommunityTest { | ||
private val peersSize = 5 | ||
private var marketCommunity = spyk(MarketCommunity(), recordPrivateCalls = true) | ||
private val myPeer = mockk<Peer>() | ||
private val endpoint = mockk<EndpointAggregator>() | ||
|
||
@Test | ||
fun broadcast_callsSendOneTimePerPeer() { | ||
val payload = mockk<TradePayload>() | ||
every { | ||
marketCommunity["serializePacket"]( | ||
any<Int>(), | ||
any<Serializable>(), | ||
any<Boolean>(), | ||
any<Peer>(), | ||
any<ByteArray>() | ||
) | ||
} returns byteArrayOf(0x00) | ||
every { marketCommunity.getPeers() } returns getFakePeers() | ||
every { marketCommunity.myPeer } returns myPeer | ||
every { marketCommunity.endpoint } returns endpoint | ||
every { endpoint.send(any<Peer>(), any()) } just runs | ||
|
||
marketCommunity.broadcast(payload) | ||
|
||
verify(exactly = peersSize) { endpoint.send(any<Peer>(), any()) } | ||
} | ||
|
||
@Test | ||
fun addListener_addsListener() { | ||
val beforeSize = marketCommunity.listenersMap[null]?.size ?: 0 | ||
marketCommunity.addListener(null, mockk()) | ||
val afterSize = marketCommunity.listenersMap[null]?.size ?: 0 | ||
assertEquals(beforeSize, afterSize - 1) | ||
} | ||
|
||
private fun getFakePeers(): List<Peer> { | ||
val peers = mutableListOf<Peer>() | ||
for (i in 1..peersSize) { | ||
peers.add(mockk()) | ||
} | ||
return peers | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/test/java/nl/tudelft/trustchain/common/messaging/TradePayloadTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package nl.tudelft.trustchain.common.messaging | ||
|
||
import nl.tudelft.trustchain.common.constants.Currency | ||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
|
||
class TradePayloadTest { | ||
@Test | ||
fun serializeOutputDeserializesToOriginal() { | ||
val payload = TradePayload( | ||
byteArrayOf(0x00), | ||
Currency.DYMBE_DOLLAR, | ||
Currency.BTC, | ||
100.0, | ||
100.0, | ||
TradePayload.Type.ASK | ||
) | ||
val serializedPayload = payload.serialize() | ||
val deserializedPayload = TradePayload.deserialize(serializedPayload).first | ||
assertEquals(payload, deserializedPayload) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...stchain/trader/ExampleInstrumentedTest.kt → ...yloadgenerator/ExampleInstrumentedTest.kt
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
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
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
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
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
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
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
Oops, something went wrong.