mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-04 04:21:19 +01:00
Add new tests to price checking
This commit is contained in:
parent
17c2f943c6
commit
416e15a96c
@ -2,11 +2,13 @@ package com.Acrobot.ChestShop.Tests;
|
|||||||
|
|
||||||
import com.Acrobot.Breeze.Utils.PriceUtil;
|
import com.Acrobot.Breeze.Utils.PriceUtil;
|
||||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||||
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Listeners.PreShopCreation.PriceChecker.onPreShopCreation;
|
import static com.Acrobot.ChestShop.Listeners.PreShopCreation.PriceChecker.onPreShopCreation;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
@ -21,20 +23,58 @@ public class PriceCheckerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrice() {
|
public void testLegalBuyPrice() {
|
||||||
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("B 1"));
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("B 1"));
|
||||||
onPreShopCreation(event);
|
onPreShopCreation(event);
|
||||||
|
assertEquals(PriceUtil.getBuyPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 1.0);
|
||||||
assertFalse(event.isCancelled());
|
assertFalse(event.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
event = new PreShopCreationEvent(null, null, getPriceString("S 1"));
|
@Test
|
||||||
|
public void testLegalSellPrice() {
|
||||||
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("S 1"));
|
||||||
onPreShopCreation(event);
|
onPreShopCreation(event);
|
||||||
|
assertEquals(PriceUtil.getSellPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 1.0);
|
||||||
assertFalse(event.isCancelled());
|
assertFalse(event.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
event = new PreShopCreationEvent(null, null, getPriceString("B 1:S 1"));
|
@Test
|
||||||
|
public void testIllegalBuyPrice() {
|
||||||
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("10 B 1"));
|
||||||
onPreShopCreation(event);
|
onPreShopCreation(event);
|
||||||
|
assertTrue(event.isCancelled());
|
||||||
|
|
||||||
|
event = new PreShopCreationEvent(null, null, getPriceString("1EB100000000000"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertTrue(event.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLegalBuyAndSellPrices() {
|
||||||
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("B 2:S 1"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(PriceUtil.getSellPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 1.0);
|
||||||
|
assertEquals(PriceUtil.getBuyPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 2.0);
|
||||||
assertFalse(event.isCancelled());
|
assertFalse(event.isCancelled());
|
||||||
|
|
||||||
event = new PreShopCreationEvent(null, null, getPriceString("BS 1"));
|
event = new PreShopCreationEvent(null, null, getPriceString("2 B:S 1"));
|
||||||
|
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(PriceUtil.getSellPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 1.0);
|
||||||
|
assertEquals(PriceUtil.getBuyPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 2.0);
|
||||||
|
assertFalse(event.isCancelled());
|
||||||
|
|
||||||
|
event = new PreShopCreationEvent(null, null, getPriceString("2 B:1 S"));
|
||||||
|
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(PriceUtil.getSellPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 1.0);
|
||||||
|
assertEquals(PriceUtil.getBuyPrice(event.getSignLine(ChestShopSign.PRICE_LINE)), 2.0);
|
||||||
|
assertFalse(event.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIllegalPrices() {
|
||||||
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("BS 1"));
|
||||||
onPreShopCreation(event);
|
onPreShopCreation(event);
|
||||||
assertTrue(event.isCancelled());
|
assertTrue(event.isCancelled());
|
||||||
|
|
||||||
@ -52,4 +92,23 @@ public class PriceCheckerTest {
|
|||||||
assertTrue(PriceUtil.getBuyPrice(priceString) == PriceUtil.NO_PRICE);
|
assertTrue(PriceUtil.getBuyPrice(priceString) == PriceUtil.NO_PRICE);
|
||||||
assertTrue(PriceUtil.getSellPrice(priceString) == PriceUtil.NO_PRICE);
|
assertTrue(PriceUtil.getSellPrice(priceString) == PriceUtil.NO_PRICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemovingTrailingZeroes() {
|
||||||
|
PreShopCreationEvent event = new PreShopCreationEvent(null, null, getPriceString("S.7500000000"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(event.getSignLine(ChestShopSign.PRICE_LINE), "S.75");
|
||||||
|
|
||||||
|
event = new PreShopCreationEvent(null, null, getPriceString("S7500000000"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(event.getSignLine(ChestShopSign.PRICE_LINE), "S7500000000");
|
||||||
|
|
||||||
|
event = new PreShopCreationEvent(null, null, getPriceString("S.75000:B.75000"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(event.getSignLine(ChestShopSign.PRICE_LINE), "S.75:B.75");
|
||||||
|
|
||||||
|
event = new PreShopCreationEvent(null, null, getPriceString("S75000:B.75000"));
|
||||||
|
onPreShopCreation(event);
|
||||||
|
assertEquals(event.getSignLine(ChestShopSign.PRICE_LINE), "S75000:B.75");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user