diff --git a/src/test/java/component_construction/storable/StorableCustomCompilerTests.java b/src/test/java/component_construction/storable/StorableCustomCompilerTests.java index 12664a6..22fa962 100644 --- a/src/test/java/component_construction/storable/StorableCustomCompilerTests.java +++ b/src/test/java/component_construction/storable/StorableCustomCompilerTests.java @@ -1,5 +1,137 @@ package component_construction.storable; +import static org.junit.jupiter.api.Assertions.*; +import java.util.Map; +import org.junit.jupiter.api.Test; + +import storage.external_interfaces.Storable; +import storage.storage_values.*; +import test_aids.storage_entities.custom_components.*; + public class StorableCustomCompilerTests { - // TODO + + @Test + public void getStorageRepresentation() { + TestStorableCustomLexicalAnalyser lexicalAnalyser = new TestStorableCustomLexicalAnalyser(); + TestStorableCustomSyntaxAnalyser syntaxAnalyser = new TestStorableCustomSyntaxAnalyser(); + TestStorableCustomCodeGenerator codeGenerator = new TestStorableCustomCodeGenerator(); + + StorableCustomCompiler compiler = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser, + codeGenerator + ); + + + MapStorageValue actualRepresentation = compiler.getStorageRepresentation(); + + + MapStorageValue expectedRepresentation = new MapStorageValue(Map.of( + "lexicalAnalyser", new ListStorageValue( + new StringStorageValue(lexicalAnalyser.getClass().getName()), + ((Storable)lexicalAnalyser).getStorageRepresentation() + ), + "syntaxAnalyser", new ListStorageValue( + new StringStorageValue(syntaxAnalyser.getClass().getName()), + ((Storable)syntaxAnalyser).getStorageRepresentation() + ), + "codeGenerator", new ListStorageValue( + new StringStorageValue(codeGenerator.getClass().getName()), + ((Storable)codeGenerator).getStorageRepresentation() + ) + )); + + assertEquals(expectedRepresentation, actualRepresentation); + } + + @Test + public void equality() { + TestStorableCustomLexicalAnalyser lexicalAnalyser = new TestStorableCustomLexicalAnalyser(); + TestStorableCustomSyntaxAnalyser syntaxAnalyser = new TestStorableCustomSyntaxAnalyser(); + TestStorableCustomCodeGenerator codeGenerator = new TestStorableCustomCodeGenerator(); + + + StorableCustomCompiler compiler1 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser, + codeGenerator + ); + StorableCustomCompiler compiler2 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser, + codeGenerator + ); + + + assertEquals(compiler1, compiler2); + } + + @Test + public void inequality_lexicalAnalyser() { + TestStorableCustomLexicalAnalyser lexicalAnalyser1 = new TestStorableCustomLexicalAnalyser("1"); + TestStorableCustomLexicalAnalyser lexicalAnalyser2 = new TestStorableCustomLexicalAnalyser("2"); + TestStorableCustomSyntaxAnalyser syntaxAnalyser = new TestStorableCustomSyntaxAnalyser(); + TestStorableCustomCodeGenerator codeGenerator = new TestStorableCustomCodeGenerator(); + + + StorableCustomCompiler compiler1 = new StorableCustomCompiler( + lexicalAnalyser1, + syntaxAnalyser, + codeGenerator + ); + StorableCustomCompiler compiler2 = new StorableCustomCompiler( + lexicalAnalyser2, + syntaxAnalyser, + codeGenerator + ); + + + assertNotEquals(compiler1, compiler2); + } + + @Test + public void inequality_syntaxAnalyser() { + TestStorableCustomLexicalAnalyser lexicalAnalyser = new TestStorableCustomLexicalAnalyser(); + TestStorableCustomSyntaxAnalyser syntaxAnalyser1 = new TestStorableCustomSyntaxAnalyser("1"); + TestStorableCustomSyntaxAnalyser syntaxAnalyser2 = new TestStorableCustomSyntaxAnalyser("2"); + TestStorableCustomCodeGenerator codeGenerator = new TestStorableCustomCodeGenerator(); + + + StorableCustomCompiler compiler1 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser1, + codeGenerator + ); + StorableCustomCompiler compiler2 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser2, + codeGenerator + ); + + + assertNotEquals(compiler1, compiler2); + } + + @Test + public void inequality_codeGenerator() { + TestStorableCustomLexicalAnalyser lexicalAnalyser = new TestStorableCustomLexicalAnalyser(); + TestStorableCustomSyntaxAnalyser syntaxAnalyser = new TestStorableCustomSyntaxAnalyser(); + TestStorableCustomCodeGenerator codeGenerator1 = new TestStorableCustomCodeGenerator("1"); + TestStorableCustomCodeGenerator codeGenerator2 = new TestStorableCustomCodeGenerator("2"); + + + StorableCustomCompiler compiler1 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser, + codeGenerator1 + ); + StorableCustomCompiler compiler2 = new StorableCustomCompiler( + lexicalAnalyser, + syntaxAnalyser, + codeGenerator2 + ); + + + assertNotEquals(compiler1, compiler2); + } } diff --git a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomCodeGenerator.java b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomCodeGenerator.java index 78e1963..e80d7d9 100644 --- a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomCodeGenerator.java +++ b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomCodeGenerator.java @@ -7,6 +7,14 @@ public class TestStorableCustomCodeGenerator implements CodeGenerator, Storable { + public String value = null; + + public TestStorableCustomCodeGenerator() {} + + public TestStorableCustomCodeGenerator(String value) { + this.value = value; + } + @Override public String generate(ParseState parseRoot) { throw new UnsupportedOperationException("Unimplemented method 'generate'"); @@ -20,6 +28,10 @@ public StorageValue getStorageRepresentation() { @Override public boolean equals(Object obj) { if (!(obj instanceof TestStorableCustomCodeGenerator)) return false; + + TestStorableCustomCodeGenerator other = (TestStorableCustomCodeGenerator)obj; + if (this.value != other.value) return false; + return true; } diff --git a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomLexicalAnalyser.java b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomLexicalAnalyser.java index b8a1055..05e66d8 100644 --- a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomLexicalAnalyser.java +++ b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomLexicalAnalyser.java @@ -7,6 +7,14 @@ public class TestStorableCustomLexicalAnalyser implements LexicalAnalyser, Storable { + public String value = null; + + public TestStorableCustomLexicalAnalyser() {} + + public TestStorableCustomLexicalAnalyser(String value) { + this.value = value; + } + @Override public Token[] analyse(String sentence) { throw new UnsupportedOperationException("Unimplemented method 'analyse'"); @@ -19,7 +27,11 @@ public StorageValue getStorageRepresentation() { @Override public boolean equals(Object obj) { - if (!(obj instanceof TestStorableCustomCodeGenerator)) return false; + if (!(obj instanceof TestStorableCustomLexicalAnalyser)) return false; + + TestStorableCustomLexicalAnalyser other = (TestStorableCustomLexicalAnalyser)obj; + if (this.value != other.value) return false; + return true; } diff --git a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomSyntaxAnalyser.java b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomSyntaxAnalyser.java index 2fef464..c47d23e 100644 --- a/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomSyntaxAnalyser.java +++ b/src/test/java/test_aids/storage_entities/custom_components/TestStorableCustomSyntaxAnalyser.java @@ -8,6 +8,14 @@ public class TestStorableCustomSyntaxAnalyser implements SyntaxAnalyser, Storable { + public String value = null; + + public TestStorableCustomSyntaxAnalyser() {} + + public TestStorableCustomSyntaxAnalyser(String value) { + this.value = value; + } + @Override public ParseState analyse(Token[] inputTokens) throws ParseFailedException { throw new UnsupportedOperationException("Unimplemented method 'analyse'"); @@ -20,7 +28,11 @@ public StorageValue getStorageRepresentation() { @Override public boolean equals(Object obj) { - if (!(obj instanceof TestStorableCustomCodeGenerator)) return false; + if (!(obj instanceof TestStorableCustomSyntaxAnalyser)) return false; + + TestStorableCustomSyntaxAnalyser other = (TestStorableCustomSyntaxAnalyser)obj; + if (this.value != other.value) return false; + return true; }