【发布时间】:2022-01-16 00:29:36
【问题描述】:
我有一个 TestEntry 类:
@Test
void testFloatConstructor() {
Entry floatTest = new Entry(1);
assertEquals(floatTest.number, 1, "Test that the constructor sets
the Entry float to 1");
}
@Test
void testSymbolConstructor() {
Symbol symbolTestSign = new Symbol(Symbol.MINUS);
Entry symbolTest = new Entry(symbolTestSign);
assertEquals(symbolTest.other, Symbol.MINUS, "Test that the
constructor sets the Symbol to - sign");
}
以及实际的Entry Class:
float number;
Symbol other;
String str;
Type type;
public Entry(float value) {
this.number = value;
}
public Entry(Symbol which) {
this.other = which;
}
testFloatConstructor() 的测试工作正常,但是当我运行 testSymbolConstructor() 时,预期 只返回我的包名(实际 是正确的,返回 -)。这是什么原因造成的?我没有正确构造符号类吗:
enum Symbols {
LEFT_BRACKET,
RIGHT_BRACKET,
TIMES,
DIVIDE,
PLUS,
MINUS,
INVALID
}
public static final String MINUS = "-";
public static final String PLUS = "+";
String symbol;
public Symbol() {
}
public Symbol(String symbol) {
this.symbol = symbol;
}
我还没有完成符号类,因为我正在使用 TDD 编程并试图让这个测试首先通过。即使使用硬编码/作弊,我也无法让它发挥作用。
感谢您的帮助!
【问题讨论】:
标签: import enums constructor tdd assert