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(虽然没用到)
- 了解了测试单元
- 知道了集合要先判空
差不多就是这样,然后时间耽误的有点长就赶紧走了,也没再多问什么
本文来自博客园,作者:紫英626,转载请注明原文链接:https://www.cnblogs.com/recorderM/p/16050134.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现