我想检查输入是否是回文(向前和向后读取相同的方式),但我不熟悉布尔值。我不知道如何定义布尔值并返回布尔值。
这是我的测试代码
@Test public void test5(){
code.Solution s = new code.Solution();
String input = "dad ";
int expected = true;
int actual = s.is Palindrome(input);
assert True("Expected was" +expected+"but the actual was" +actual , expected == actual);
}
我真的不知道如何定义我的解决方法。
答案 0 :(得分:1)
Boolean数据类型只有两种状态:true和false。你的isPalindrome函数应该首先返回一个布尔值。一旦它完成,测试将如下所示:
boolean expected = true;
boolean actual = s.is Palindrome(input);
assertEquals(expected, actual);
答案 1 :(得分:0)
使用assertEquals
方法。
@Test public void test5(){
code.Solution s = new code.Solution();
String input = "dad ";
boolean expected = true;
boolean actual = s.is Palindrome(input);
assertEquals(expected, actual);
}
另外,将预期变量和实际变量更改为boolean而不是int。