我四处寻找类似的问题,但找不到解决方案。
我有几个相同类型对象的实例。举一个简单的例子,一个 Pen 对象。此类包含大小(Int)和颜色(String)属性。我需要模拟一个接受这种类型对象的函数(例如calculatePrice)。我希望它根据其中一个属性返回结果。
every { calculatePrice(pen : Pen) } returns 3
every { calculatePrice(pen2 : Pen) } returns 4
Run Code Online (Sandbox Code Playgroud)
由于此调用嵌套在另一个函数中,因此我无法保证对象的地址相同,因此我尝试通过检查属性值(例如 pen.size)来解决此问题。如果有一种方法可以确保对象的值相同,而不是引用相同,那也可以解决我的问题。
使用 Mockito,我会使用 argThat(pen -> pen.size() == 2)
任何建议将不胜感激。
我确信这是一个简单的问题.老实说,这应该是编写SAT求解器最简单的部分,但是,我应该有这样的用户输入数据:
Sample Input:
1 <-- 1st number denotes the number of cases I will have
5 <-- 2nd number represents the number of variables, followed
1 2 3 who knows how many clauses.
-1 3 4
-2 -3 5
-5 -1 2
-4 1 -2
-4 -1 -2 -3 -5
*blank line separates the different cases*
.... followed by as many cases as the user said they had
Run Code Online (Sandbox Code Playgroud)
所以,我将这些子句存储到字符串向量中,并且它们都会进入另一个向量.那么从用户那里获得此输入的最佳方法是什么?最初没有给出条款数量的事实是让我感到困惑的部分.我会尝试一会儿()...但我不知道如何终止它.我想我有点不确定cin在这种情况下会如何工作.
感谢你的帮助.