Convert some test classes to kotlin
This commit is contained in:
parent
0fb64f0a2d
commit
c04f4b6c51
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="RemoveRedundantBackticks" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
47
pom.xml
47
pom.xml
|
@ -11,9 +11,14 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.version>1.2.30</kotlin.version>
|
||||
<junit5.version>5.1.0</junit5.version>
|
||||
<skipTests>false</skipTests>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<!--<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>-->
|
||||
<!--<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>-->
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -91,7 +96,27 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.20.1</version>
|
||||
<version>2.19.1</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
|
@ -145,9 +170,23 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.9.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
package table;
|
||||
|
||||
import error.Severity;
|
||||
import function.FunctionNames;
|
||||
import function.LispFunction;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import sexpression.Cons;
|
||||
import sexpression.SExpression;
|
||||
import table.FunctionTable.LispFunctionInstantiationException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static sexpression.Nil.NIL;
|
||||
import static sexpression.Symbol.T;
|
||||
import static table.FunctionTable.defineFunction;
|
||||
import static table.FunctionTable.isAlreadyDefined;
|
||||
import static table.FunctionTable.lookupFunction;
|
||||
import static table.FunctionTable.resetFunctionTable;
|
||||
|
||||
public class FunctionTableTest {
|
||||
|
||||
@FunctionNames({ "GOOD" })
|
||||
public static class GoodFunction extends LispFunction {
|
||||
|
||||
public GoodFunction(String name) {}
|
||||
|
||||
@Override
|
||||
public SExpression call(Cons argumentList) {
|
||||
return NIL;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionNames({ "BAD" })
|
||||
public static class BadFunction extends LispFunction {
|
||||
|
||||
@Override
|
||||
public SExpression call(Cons argumentList) {
|
||||
return NIL;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UglyFunction extends LispFunction {
|
||||
|
||||
@Override
|
||||
public SExpression call(Cons argumentList) {
|
||||
return NIL;
|
||||
}
|
||||
}
|
||||
|
||||
private LispFunction createLispFunction() {
|
||||
return new LispFunction() {
|
||||
|
||||
@Override
|
||||
public SExpression call(Cons argumentList) {
|
||||
return T;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
resetFunctionTable();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
resetFunctionTable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builtInFunctionIsDefined() {
|
||||
assertTrue(isAlreadyDefined("CONS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undefinedFunctionIsNotDefined() {
|
||||
assertFalse(isAlreadyDefined("undefined"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupBuiltInFunction_ReturnsFunction() {
|
||||
assertNotNull(lookupFunction("CONS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupUndefinedFunction_ReturnsNull() {
|
||||
assertNull(lookupFunction("undefined"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defineFunctionWorks() {
|
||||
String functionName = "testFunction";
|
||||
LispFunction testFunction = createLispFunction();
|
||||
|
||||
assertNull(lookupFunction(functionName));
|
||||
assertFalse(isAlreadyDefined(functionName));
|
||||
|
||||
defineFunction(functionName, testFunction);
|
||||
|
||||
assertTrue(isAlreadyDefined(functionName));
|
||||
assertEquals(testFunction, lookupFunction(functionName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetFunctionTableWorks() {
|
||||
String functionName = "testFunction";
|
||||
LispFunction testFunction = createLispFunction();
|
||||
defineFunction(functionName, testFunction);
|
||||
|
||||
resetFunctionTable();
|
||||
|
||||
assertFalse(isAlreadyDefined(functionName));
|
||||
assertNull(lookupFunction(functionName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetWithCustomBuitIns() {
|
||||
Set<Class<? extends LispFunction>> goodBuiltIns = new HashSet<>();
|
||||
goodBuiltIns.add(GoodFunction.class);
|
||||
|
||||
resetFunctionTable(goodBuiltIns);
|
||||
|
||||
assertTrue(isAlreadyDefined("GOOD"));
|
||||
assertNotNull(lookupFunction("GOOD"));
|
||||
}
|
||||
|
||||
@Test(expected = LispFunctionInstantiationException.class)
|
||||
public void unableToInitializeBuiltIn() {
|
||||
Set<Class<? extends LispFunction>> badBuiltIns = new HashSet<>();
|
||||
badBuiltIns.add(BadFunction.class);
|
||||
|
||||
resetFunctionTable(badBuiltIns);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lispFunctionInstantiationException_HasCorrectAttributes() {
|
||||
LispFunctionInstantiationException e = new LispFunctionInstantiationException("Bad");
|
||||
|
||||
assertNotNull(e.getMessage());
|
||||
assertTrue(e.getMessage().length() > 0);
|
||||
assertEquals(Severity.CRITICAL, e.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namelessBuiltIn_DoesNotCauseNPE() {
|
||||
Set<Class<? extends LispFunction>> namelessBuiltins = new HashSet<>();
|
||||
namelessBuiltins.add(UglyFunction.class);
|
||||
|
||||
resetFunctionTable(namelessBuiltins);
|
||||
|
||||
assertFalse(isAlreadyDefined("UGLY"));
|
||||
assertNull(lookupFunction("UGLY"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
package table
|
||||
|
||||
import error.Severity
|
||||
import function.FunctionNames
|
||||
import function.LispFunction
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
|
||||
import sexpression.Cons
|
||||
import sexpression.Nil
|
||||
import sexpression.Nil.NIL
|
||||
import sexpression.Symbol.T
|
||||
import table.FunctionTable.LispFunctionInstantiationException
|
||||
import table.FunctionTable.defineFunction
|
||||
import table.FunctionTable.isAlreadyDefined
|
||||
import table.FunctionTable.lookupFunction
|
||||
import table.FunctionTable.resetFunctionTable
|
||||
import java.util.HashSet
|
||||
|
||||
@TestInstance(PER_CLASS)
|
||||
class FunctionTableTest {
|
||||
|
||||
@FunctionNames("GOOD")
|
||||
class GoodFunction(name: String) : LispFunction() {
|
||||
|
||||
override fun call(argumentList: Cons): Nil = NIL
|
||||
}
|
||||
|
||||
@FunctionNames("BAD")
|
||||
class BadFunction : LispFunction() {
|
||||
|
||||
override fun call(argumentList: Cons): Nil = NIL
|
||||
}
|
||||
|
||||
class UglyFunction : LispFunction() {
|
||||
|
||||
override fun call(argumentList: Cons): Nil = NIL
|
||||
}
|
||||
|
||||
private fun createLispFunction() = object : LispFunction() {
|
||||
override fun call(argumentList: Cons) = T
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun initialize() {
|
||||
resetFunctionTable()
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun tearDown() {
|
||||
resetFunctionTable()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun builtInFunctionIsDefined() {
|
||||
assertThat(isAlreadyDefined("CONS")).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun undefinedFunctionIsNotDefined() {
|
||||
assertThat(isAlreadyDefined("undefined")).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lookupBuiltInFunction_ReturnsFunction() {
|
||||
assertThat(lookupFunction("CONS")).isNotNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lookupUndefinedFunction_ReturnsNull() {
|
||||
assertThat(lookupFunction("undefined")).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun defineFunctionWorks() {
|
||||
val functionName = "testFunction"
|
||||
val testFunction = createLispFunction()
|
||||
|
||||
assertThat(lookupFunction(functionName)).isNull()
|
||||
assertThat(isAlreadyDefined(functionName)).isFalse()
|
||||
|
||||
defineFunction(functionName, testFunction)
|
||||
|
||||
assertThat(isAlreadyDefined(functionName)).isTrue()
|
||||
assertThat(lookupFunction(functionName)).isEqualTo(testFunction)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetFunctionTableWorks() {
|
||||
val functionName = "testFunction"
|
||||
val testFunction = createLispFunction()
|
||||
defineFunction(functionName, testFunction)
|
||||
|
||||
resetFunctionTable()
|
||||
|
||||
assertThat(lookupFunction(functionName)).isNull()
|
||||
assertThat(isAlreadyDefined(functionName)).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetWithCustomBuitIns() {
|
||||
val goodBuiltIns = HashSet<Class<out LispFunction>>()
|
||||
goodBuiltIns.add(GoodFunction::class.java)
|
||||
|
||||
resetFunctionTable(goodBuiltIns)
|
||||
|
||||
assertThat(isAlreadyDefined("GOOD")).isTrue()
|
||||
assertThat(lookupFunction("GOOD")).isNotNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unableToInitializeBuiltIn() {
|
||||
val badBuiltIns = HashSet<Class<out LispFunction>>()
|
||||
badBuiltIns.add(BadFunction::class.java)
|
||||
|
||||
assertThrows(LispFunctionInstantiationException::class.java) { resetFunctionTable(badBuiltIns) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lispFunctionInstantiationException_HasCorrectAttributes() {
|
||||
val e = LispFunctionInstantiationException("Bad")
|
||||
|
||||
assertThat(e.message).isNotEmpty()
|
||||
assertThat(e.severity).isEqualTo(Severity.CRITICAL)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun namelessBuiltIn_DoesNotCauseNPE() {
|
||||
val namelessBuiltins = HashSet<Class<out LispFunction>>()
|
||||
namelessBuiltins.add(UglyFunction::class.java)
|
||||
|
||||
resetFunctionTable(namelessBuiltins)
|
||||
|
||||
assertThat(isAlreadyDefined("UGLY")).isFalse()
|
||||
assertThat(lookupFunction("UGLY")).isNull()
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package table;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static sexpression.Nil.NIL;
|
||||
import static sexpression.Symbol.T;
|
||||
|
||||
public class SymbolTableTest {
|
||||
|
||||
private SymbolTable symbolTable;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
symbolTable = new SymbolTable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupSymbolNotInTable() {
|
||||
assertFalse(symbolTable.contains("symbol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupSymbolInTable() {
|
||||
symbolTable.put("symbol", T);
|
||||
|
||||
assertTrue(symbolTable.contains("symbol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveSymbolValue() {
|
||||
symbolTable.put("symbol", T);
|
||||
|
||||
assertEquals(T, symbolTable.get("symbol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redefineSymbolValue() {
|
||||
symbolTable.put("symbol", T);
|
||||
symbolTable.put("symbol", NIL);
|
||||
|
||||
assertEquals(NIL, symbolTable.get("symbol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkParentTableIsCorrect() {
|
||||
SymbolTable childTable = new SymbolTable(symbolTable);
|
||||
|
||||
assertEquals(symbolTable, childTable.getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupSymbolInParentTable() {
|
||||
symbolTable.put("symbol", T);
|
||||
SymbolTable childTable = new SymbolTable(symbolTable);
|
||||
SymbolTable parentTable = childTable.getParent();
|
||||
|
||||
assertEquals(T, parentTable.get("symbol"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package table
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
|
||||
import sexpression.Nil.NIL
|
||||
import sexpression.Symbol.T
|
||||
|
||||
@TestInstance(PER_CLASS)
|
||||
class SymbolTableTest {
|
||||
|
||||
private lateinit var symbolTable: SymbolTable
|
||||
|
||||
@BeforeEach
|
||||
fun initialize() {
|
||||
symbolTable = SymbolTable()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lookup a symbol that does not exist`() {
|
||||
assertThat(symbolTable.contains("symbol")).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lookup a symbol that exists`() {
|
||||
symbolTable.put("symbol", T)
|
||||
|
||||
assertThat(symbolTable.contains("symbol")).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get the value of a symbol`() {
|
||||
symbolTable.put("symbol", T)
|
||||
|
||||
assertThat(symbolTable.get("symbol")).isEqualTo(T)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `redefine the value of a symbol`() {
|
||||
symbolTable.put("symbol", T)
|
||||
symbolTable.put("symbol", NIL)
|
||||
|
||||
assertThat(symbolTable.get("symbol")).isEqualTo(NIL)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `check the value of a parent table`() {
|
||||
val childTable = SymbolTable(symbolTable)
|
||||
|
||||
assertThat(childTable.parent).isEqualTo(symbolTable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lookup a symbol in a parent table`() {
|
||||
symbolTable.put("symbol", T)
|
||||
val childTable = SymbolTable(symbolTable)
|
||||
val parentTable = childTable.parent
|
||||
|
||||
assertThat(parentTable.get("symbol")).isEqualTo(T)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue