ThoughtWorks一面

1.在github上clone了一个java的仓库

https://github.com/techops-recsys-grad-hiring/joi-grad-shopping-cart-java

这个是说明:

Existing Business Rules
Application code currently has following rules:

Calculates total price and total loyalty points earned by the customer.
Products with product code starting with DIS_10 have a 10% discount applied.
Products with product code starting with DIS_15 have a 15% discount applied.
Loyalty points are earned more when the product is not under any offer.
Customer earns 1 point on every $5 purchase.
Customer earns 1 point on every $10 spent on a product with 10% discount.
Customer earns 1 point on every $15 spent on a product with 15% discount.

2.加了一个相似的逻辑,直接复制粘贴前面的改了改数

3.如果加一个买二赠一的商品要怎么报价

然后讨论了半天买二赠一的逻辑,比如四个商品怎么算 是算两个买二赠一还是 一个买二赠一加上一个原价

然后一致同意先和3取余,然后剩下的如果是两个就算0.67的原价,一个就原价

然后走了0个商品的测试用例

 //买二赠一
    @Test
    public void countForBULKDiscount() {
        List<Product> products = null;
        ShoppingCart cart = new ShoppingCart(customer, products);
        Order order = cart.checkout();
        assertEquals(0, order.getLoyaltyPoints());
        assertEquals(0, order.getTotalPrice(),0.0);
    }

然后判断集合的时候

先判断是否为null,再看size(),不然会报空指针异常:这里顺序不能变

 if (products == null || products.size() == 0) {

            return new Order(0, 0);

        }

收获

  • 学会了git和在idea上使用git(虽然没用到)
  • 了解了测试单元
  • 知道了集合要先判空

差不多就是这样,然后时间耽误的有点长就赶紧走了,也没再多问什么

posted @ 2022-03-24 15:58  紫英626  阅读(602)  评论(0编辑  收藏  举报

紫英