Skip to content

Commit

Permalink
updated test after revision
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian.costin.marin committed Nov 20, 2024
1 parent 2fd712d commit 49a3c85
Showing 1 changed file with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.monticore.symbols.oosymbols._symboltable.*;
import de.monticore.types.check.SymTypeExpression;
import de.monticore.types.check.SymTypeOfGenerics;
import de.monticore.types.check.SymTypeOfTuple;
import de.se_rwth.commons.logging.Log;
import de.se_rwth.commons.logging.LogStub;
import org.junit.jupiter.api.Assertions;
Expand All @@ -21,6 +22,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class StreamTypeTest {

Expand All @@ -38,7 +40,7 @@ public void init() throws URISyntaxException {
}

@Test
public void resolveStreamType() {
public void testStreamTypeResolution() {
Optional<TypeSymbol> streamOpt = OOSymbolsMill.globalScope()
.resolveType("Stream");
Assertions.assertTrue(streamOpt.isPresent());
Expand All @@ -49,76 +51,98 @@ public void resolveStreamType() {
}

@Test
public void resolveStaticEmpty() {
MethodSymbol method = resolveMethod("Stream.emptyStream");
Assertions.assertTrue(method.getParameterList().isEmpty());
public void testStaticRepeat() {
MethodSymbol method = resolveMethod("Stream.repeat");
Assertions.assertEquals(method.getParameterList().size(), 2);
assertIsStreamWithTypeVar(method.getType());
Assertions.assertTrue(method.isIsStatic());
List<TypeVarSymbol> typeVars = method.getSpannedScope().getLocalTypeVarSymbols();
Assertions.assertEquals(1, typeVars.size());
Assertions.assertNotEquals(typeVars.get(0).getName(), "T");
Assertions.assertNotEquals(typeVars.get(0).getName(), "S");
}

@Test
public void resolveStreamMethodAppendFirst() {
MethodSymbol method = resolveMethod("Stream.appendFirst");
public void testStaticProjection() {
MethodSymbol method = resolveMethod("Stream.projFst");
Assertions.assertTrue(method.isIsStatic());
Assertions.assertEquals(2, method.getParameterList().size());
Assertions.assertTrue(method.getParameterList().get(0).getType().isTypeVariable());
assertIsStreamWithTypeVar(method.getParameterList().get(1).getType());
Assertions.assertEquals(1, method.getParameterList().size());
assertIsStreamWithTypeVar(method.getType());
assertIsStreamWithTupleOfTypeVars(method.getParameterList().get(0).getType());
}

@Test
public void resolveStreamMethodLen() {
public void testStreamMethodLen() {
MethodSymbol method = resolveMethod("Stream.len");
Assertions.assertEquals(0, method.getParameterList().size());
Assertions.assertTrue(method.getEnclosingScope().getSpanningSymbol() instanceof TypeSymbol);
Assertions.assertInstanceOf(TypeSymbol.class, method.getEnclosingScope().getSpanningSymbol());
Assertions.assertEquals("Stream", method.getEnclosingScope().getSpanningSymbol().getName());
Assertions.assertEquals(BasicSymbolsMill.LONG, method.getType().getTypeInfo().getName());
}

@Test
public void resolveStreamFunctions() {
resolveCommonMemberMethods("Stream");
public void resolveStreamMethodsTest() {
resolveCommonMemberMethods("UntimedStream");
resolveCommonMemberMethods("EventStream");
resolveCommonMemberMethods("SyncStream");
resolveCommonMemberMethods("ToptStream");
}

@Test
public void testInterfaceMethodResolution() {
resolveStaticMethods("Stream");
// methods such as "zip", "first", "nth" are not in the interface
// as the signatures do not match between implementations
resolveMethod("Stream.len");
resolveMethod("Stream.hasInfiniteLen");
resolveMethod("Stream.take");
resolveMethod("Stream.dropFirst");
resolveMethod("Stream.dropMultiple");
resolveMethod("Stream.times");
resolveMethod("Stream.infTimes");
resolveMethod("Stream.map");
resolveMethod("Stream.filter");
resolveMethod("Stream.takeWhile");
resolveMethod("Stream.dropWhile");
resolveMethod("Stream.rcDups");
resolveMethod("Stream.values");
resolveMethod("Stream.scanl");
}

protected void resolveStaticMethods(String streamType) {
resolveMethod(streamType + ".emptyStream");
resolveMethod(streamType + ".appendFirst");
resolveMethod(streamType + ".conc");
resolveMethod(streamType + ".repeat");
resolveMethod(streamType + ".iterate");
}

protected void resolveCommonMemberMethods(String streamType) {
resolveMethod(streamType + ".len");
resolveMethod(streamType + ".hasInfiniteLen");
resolveMethod(streamType + ".first");
resolveMethod(streamType + ".dropFirst");
resolveMethod(streamType + ".nth");
resolveMethod(streamType + ".take");
resolveMethod(streamType + ".drop");
resolveMethod(streamType + ".dropFirst");
resolveMethod(streamType + ".dropMultiple");
resolveMethod(streamType + ".times");
resolveMethod(streamType + ".infTimes");
resolveMethod(streamType + ".map");
resolveMethod(streamType + ".filter");
resolveMethod(streamType + ".takeWhile");
resolveMethod(streamType + ".dropWhile");
resolveMethod(streamType + ".rcDups");
resolveMethod(streamType + ".zip");
resolveMethod(streamType + ".values");
resolveMethod(streamType + "scanl");
}

@Test
public void resolveTimedStreamMethods() {
public void testTimedStreamMethodsResolution() {
resolveMethod("EventStream.delay");
resolveMethod("EventStream.mapSlice");
resolveMethod("EventStream.rougherTime");
resolveMethod("EventStream.finerTime");
resolveMethod("EventStream.sync");
resolveMethod("EventStream.topt");
resolveMethod("EventStream.untimed");
resolveMethod("ToptStream.sizeEps");
resolveMethod("ToptStream.sizeEmptyTimeslices");
resolveMethod("SyncStream.event");
}

Expand All @@ -135,6 +159,18 @@ protected void assertIsStreamWithTypeVar(SymTypeExpression type) {
Assertions.assertTrue(((SymTypeOfGenerics) type).getArgument(0).isTypeVariable());
}

protected void assertIsStreamWithTupleOfTypeVars(SymTypeExpression type) {
Assertions.assertNotNull(type);
Assertions.assertTrue(type.isGenericType());
Assertions.assertEquals("Stream", type.getTypeInfo().getName());
Assertions.assertEquals(1, ((SymTypeOfGenerics) type).getArgumentList().size());
Assertions.assertTrue(((SymTypeOfGenerics) type).getArgument(0).isTupleType());
Assertions.assertEquals(2, ((SymTypeOfTuple)((SymTypeOfGenerics) type).getArgument(0)).getTypeList().size());
List<SymTypeExpression> tuple = ((SymTypeOfTuple)((SymTypeOfGenerics) type).getArgument(0)).getTypeList();
Assertions.assertTrue(tuple.get(0).isTypeVariable());
Assertions.assertTrue(tuple.get(1).isTypeVariable());
}

protected MethodSymbol resolveMethod(String name) {
Optional<MethodSymbol> emptyOpt = OOSymbolsMill.globalScope().resolveMethod(name);
Assertions.assertTrue(emptyOpt.isPresent());
Expand Down

0 comments on commit 49a3c85

Please sign in to comment.