import domains.Item;
import domains.Pos;
import domains.ShoppingChart;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * Created by Administrator on 2014/12/28.
 */
public class PosTest {
    @Test
    public void testGetCorrectShoppingListForSingleItem() throws Exception {
        // given
        Item cokeCola = new Item("ITEM000000", "可口可乐", "瓶", 3.00);
        ShoppingChart shoppingChart = new ShoppingChart();
        shoppingChart.add(cokeCola);

        // when
        Pos pos = new Pos();
        String actualShoppingList = pos.getShoppingList(shoppingChart);

        // then
        String expectedShoppingList =
                          "***商店购物清单***\n"
                        + "名称：可口可乐，数量：1瓶，单价：3.00(元)，小计：3.00(元)\n"
                        + "----------------------\n"
                        + "总计：3.00(元)\n"
                        + "**********************\n";
        assertThat(actualShoppingList, is(expectedShoppingList));
    }

    @Test
    public void testGetCorrectShoppingListForTwoSameItems() throws Exception {
        // given
        ShoppingChart shoppingChart = new ShoppingChart();
        shoppingChart.add(new Item("ITEM000000", "可口可乐", "瓶", 3.00));
        shoppingChart.add(new Item("ITEM000000", "可口可乐", "瓶", 3.00));

        // when
        Pos pos = new Pos();
        String actualShoppingList = pos.getShoppingList(shoppingChart);

        // then
        String expectedShoppingList =
                          "***商店购物清单***\n"
                        + "名称：可口可乐，数量：2瓶，单价：3.00(元)，小计：6.00(元)\n"
                        + "----------------------\n"
                        + "总计：6.00(元)\n"
                        + "**********************\n";
        assertThat(actualShoppingList, is(expectedShoppingList));
    }

    @Test
    public void testGetCorrectShoppingListForReq1() throws Exception {
        //given
        ShoppingChart shoppingChart = new ShoppingChart();
        shoppingChart.add(new Item("ITEM000000","可口可乐","瓶",3.00));
        shoppingChart.add(new Item("ITEM000000","可口可乐","瓶",3.00));
        shoppingChart.add(new Item("ITEM000000","可口可乐","瓶",3.00));
        shoppingChart.add(new Item("ITEM000000","可口可乐","瓶",3.00));
        shoppingChart.add(new Item("ITEM000000","可口可乐","瓶",3.00));
        shoppingChart.add(new Item("ITEM000001","雪碧","瓶",3.00));
        shoppingChart.add(new Item("ITEM000001","雪碧","瓶",3.00));
        shoppingChart.add(new Item("ITEM000004","电池","个",2.00));

        //when
        Pos pos = new Pos();
        String actualShoppingList = pos.getShoppingList(shoppingChart);

        //then
        String expectedShoppingList =
                "***商店购物清单***\n"
                        + "名称：可口可乐，数量：5瓶，单价：3.00(元)，小计：15.00(元)\n"
                        + "名称：雪碧，数量：2瓶，单价：3.  元)，小计：6.00(元)\n"
                        + "名称：电池，数量：1个，单价：2.00(元)，小计：2.00(元)\n"
                        + "----------------------\n"
                        + "总计：23.00(元)\n"
                        + "**********************\n";
        assertThat(actualShoppingList, is(expectedShoppingList));

    }

    @Test
    public void testGetCorrectShoppingListForReq2() throws Exception {
        //given
        ShoppingChart shoppingChart = new ShoppingChart();
        shoppingChart.add(new Item("ITEM000004","电池","个",2.00,0.8));

        //when
        Pos pos = new Pos();
        String actualShoppingList = pos.getShoppingList(shoppingChart);

        //then
        String expectedShoppingList =
                "***商店购物清单***\n"
                        + "名称：电池，数量：1个，单价：2.00(元)，小计：1.60(元)\n"
                        + "----------------------\n"
                        + "总计：1.60(元)\n"
                        + "节省：0.40(元)\n"
                        + "**********************\n";
        assertThat(actualShoppingList, is(expectedShoppingList));

    }
}
@@ -1230,33 +1230,33 @@
 TEM00000
-0
+5
 %22, %22
-%E5%8F%AF%E5%8F%A3%E5%8F%AF%E4%B9%90
+%E5%90%B9%E9%A3%8E%E6%9C%BA
 %22, %22
-%E7%93%B6
+%E4%BB%B6
 %22, 
+8
 3.00));%0A
@@ -1300,33 +1300,33 @@
 TEM00000
-0
+5
 %22, %22
-%E5%8F%AF%E5%8F%A3%E5%8F%AF%E4%B9%90
+%E5%90%B9%E9%A3%8E%E6%9C%BA
 %22, %22
-%E7%93%B6
+%E4%BB%B6
 %22, 
+8
 3.00));%0A
@@ -1575,22 +1575,22 @@
 %22%E5%90%8D%E7%A7%B0%EF%BC%9A
-%E5%8F%AF%E5%8F%A3%E5%8F%AF%E4%B9%90
+%E5%90%B9%E9%A3%8E%E6%9C%BA
 %EF%BC%8C%E6%95%B0%E9%87%8F%EF%BC%9A2
-%E7%93%B6
+%E4%BB%B6
 %EF%BC%8C%E5%8D%95%E4%BB%B7%EF%BC%9A
+8
 3.00
@@ -1592,24 +1592,26 @@
 83.00(%E5%85%83)%EF%BC%8C%E5%B0%8F%E8%AE%A1%EF%BC%9A
+16
 6.00(%E5%85%83)%5Cn%22%0A 
@@ -1692,16 +1692,18 @@
   + %22%E6%80%BB%E8%AE%A1%EF%BC%9A
+16
 6.00(%E5%85%83)%5C

change the type of goods for two same items test