@Test public void add_itemA100の実行後はgetNum_itemA100は2を返す() throws Exception { // Exercise sut.add(itemA100); // Verify assertThat(sut.getNum(itemA100), is(2)); }
@Test public void add_itemA200の実行後はget_itemAは2を返す() throws Exception { // SetUp Item itemA200 = new Item("A", 200); // Exercise sut.add(itemA200); // Verify assertThat(sut.getNum(itemA100), is(2)); }
@Test public void add_itemB200の実行後はgetNum_itemB200は1を返す() throws Exception { // SetUp Item itemB200 = new Item("B", 200); // Exercise sut.add(itemB200); // Verify assertThat(sut.getNum(itemB200), is(1)); }
@Test public void getNum_itemA100は1を返す() throws Exception { // Exercise // Verify assertThat(sut.getNum(itemA100), is(1)); }
@Before public void setUp() throws Exception { sut = new ItemStock(); itemA100 = new Item("A", 100); sut.add(itemA100); }
/** * returns a page of prices * * @param pageNum page to lookup (-1 will print all pages) * @param isPlayer if should use minecraft font spacing * @param pageSize how many on a page * @param listing format to output listing with * @param header page header (<page> of <pages>) * @param footer page footer * @param showIllegal whether illegal items should be included in the listing * @param showDec whether to round to whole numbers or show 2 decimal places * @param stock what to use for stock, if applicable * @param discount percentage to mark the price down * @return a list of formatted lines * @throws SQLException if using MySQL database & there was some database connection error * @throws Exception some serious error occurred (details in message) */ public List<String> getShopListPage( int pageNum, boolean isPlayer, int pageSize, String listing, String header, String footer, boolean showIllegal, boolean showDec, ItemStock stock, double discount) throws SQLException, Exception { LinkedList<String> ret = new LinkedList<String>(); if (databaseType == DBType.MYSQL && !useCache) { updateCache(false); // manually update } else { updateCache(); } int pricelistsize = getShopSize(showIllegal); // priceList.size(); int pages = (int) Math.ceil((double) pricelistsize / pageSize); int pageStart; if (pageNum <= 0) { // pageNum = 1; pageStart = 0; pageSize = pricelistsize; } else { pageStart = getShopPageStart(pageNum - 1, pageSize, showIllegal); } String listhead = header == null || header.length() == 0 ? "" : header .replace("<page>", pageNum < 0 ? "(All)" : String.valueOf(pageNum)) .replace("<pages>", String.valueOf(pages)); if (pageNum > pages) { ret.add("There is no page " + pageNum + ". (" + pages + " pages total)"); } else { if (listhead.length() > 0) { ret.add(String.format(listhead, pageNum, pages)); } listing = listing .replace("<item>", "%1$s") .replace("<buyprice>", "%2$s") .replace("<sellprice>", "%3$s") .replace("<avail>", "%4$s"); /// for (int i = pageSize * (pageNum - 1), n = 0; n < pageSize && i < priceList.size(); ++i, // ++n) { for (int i = pageStart, n = 0; n < pageSize && i < priceList.size(); ++i, ++n) { PriceListItem it = priceList.get(i); if ((!showIllegal && !it.IsLegal()) || (it.buy < 0 && it.sell < 0)) { --n; continue; } long st = stock != null ? stock.getItemAmount(it) : -1; double buy = it.buy, sell = it.sell; if (discount != 0) { buy -= buy * discount; sell -= sell * discount; } ret.add( String.format( listing, it.coloredName(), String.format( "%5s", buy < 0 ? " No " : (showDec ? String.format("%01.2f", buy) : String.valueOf((int) Math.round(buy)))), String.format( "%5s", sell < 0 ? " No " : (showDec ? String.format("%01.2f", sell) : String.valueOf((int) Math.round(sell)))), (st < 0 ? "INF" : String.valueOf(st)))); } if (footer != null && footer.length() > 0) { ret.add(footer); } } if (ret.size() > 2) { // format spaces return MinecraftChatStr.alignTags(ret, isPlayer); } return ret; }