Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand All @@ -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;
}

Expand Down
Loading