-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the ignored tests on CircleCI
- Loading branch information
Showing
15 changed files
with
163 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,16 @@ | |
* @author Masaki Waga {@literal <[email protected]>} | ||
*/ | ||
@RequiredArgsConstructor | ||
public class ExtendedSignalMapper { | ||
public class ExtendedSignalMapper implements SignalMapper { | ||
final private List<Function<ExtendedIOSignalPiece<List<Double>>, Double>> sigMap; | ||
|
||
public ExtendedSignalMapper() { | ||
this.sigMap = Collections.emptyList(); | ||
} | ||
|
||
|
||
//@ requires 0 <= index < size() | ||
public double apply(int index, ExtendedIOSignalPiece<List<Double>> concreteSignal) { | ||
return this.sigMap.get(index).apply(concreteSignal); | ||
public double apply(int index, IOSignalPiece<List<Double>> concreteSignal) { | ||
return this.sigMap.get(index).apply((ExtendedIOSignalPiece<List<Double>>) concreteSignal); | ||
} | ||
|
||
//@ ensures \result >= 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,14 @@ | ||
package net.maswag; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.tree.ParseTree; | ||
|
||
import java.io.*; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Class to construct pseudo signals from concrete signals | ||
* | ||
* @author Masaki Waga {@literal <[email protected]>} | ||
* Interface to construct pseudo signals from concrete signals | ||
*/ | ||
@RequiredArgsConstructor | ||
public class SignalMapper { | ||
final private List<Function<IOSignalPiece<List<Double>>, Double>> sigMap; | ||
|
||
public SignalMapper() { | ||
this.sigMap = Collections.emptyList(); | ||
} | ||
|
||
|
||
public interface SignalMapper { | ||
//@ requires 0 <= index < size() | ||
public double apply(int index, IOSignalPiece<List<Double>> concreteSignal) { | ||
return this.sigMap.get(index).apply(concreteSignal); | ||
} | ||
double apply(int index, IOSignalPiece<List<Double>> concreteSignal); | ||
|
||
//@ ensures \result >= 0 | ||
public int size() { | ||
return this.sigMap.size(); | ||
} | ||
|
||
public static SignalMapper parse(String filename) throws IOException { | ||
return SignalMapper.parse(new BufferedReader( | ||
new InputStreamReader(new FileInputStream(filename)))); | ||
} | ||
|
||
public static SignalMapper parse(BufferedReader reader) { | ||
List<Function<IOSignalPiece<List<Double>>, Double>> rawList = | ||
reader.lines().map(SignalMapper::lineParse).collect(Collectors.toList()); | ||
|
||
return new SignalMapper(rawList); | ||
} | ||
|
||
static Function<IOSignalPiece<List<Double>>, Double> lineParse(String line) { | ||
net.maswag.SignalMapperVisitor<Function<IOSignalPiece<List<Double>>, Double>> visitor = new SignalMapperVisitorImpl(); | ||
return parseSignalMapperImpl(line, visitor); | ||
} | ||
|
||
private static Function<IOSignalPiece<List<Double>>, Double> parseSignalMapperImpl(String line, net.maswag.SignalMapperVisitor<Function<IOSignalPiece<List<Double>>, Double>> visitor) { | ||
CharStream stream = CharStreams.fromString(line); | ||
net.maswag.SignalMapperLexer lexer = new net.maswag.SignalMapperLexer(stream); | ||
CommonTokenStream tokens = new CommonTokenStream(lexer); | ||
net.maswag.SignalMapperParser parser = new net.maswag.SignalMapperParser(tokens); | ||
ParseTree tree = parser.expr(); | ||
return visitor.visit(tree); | ||
} | ||
int size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.maswag; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
import org.antlr.v4.runtime.tree.ParseTree; | ||
|
||
import java.io.*; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Class to construct pseudo signals from concrete signals | ||
* | ||
* @author Masaki Waga {@literal <[email protected]>} | ||
*/ | ||
@RequiredArgsConstructor | ||
public class SimpleSignalMapper implements SignalMapper { | ||
final private List<Function<IOSignalPiece<List<Double>>, Double>> sigMap; | ||
|
||
public SimpleSignalMapper() { | ||
this.sigMap = Collections.emptyList(); | ||
} | ||
|
||
//@ requires 0 <= index < size() | ||
@Override | ||
public double apply(int index, IOSignalPiece<List<Double>> concreteSignal) { | ||
return this.sigMap.get(index).apply(concreteSignal); | ||
} | ||
|
||
//@ ensures \result >= 0 | ||
@Override | ||
public int size() { | ||
return this.sigMap.size(); | ||
} | ||
|
||
public static SignalMapper parse(String filename) throws IOException { | ||
return SimpleSignalMapper.parse(new BufferedReader( | ||
new InputStreamReader(new FileInputStream(filename)))); | ||
} | ||
|
||
public static SignalMapper parse(BufferedReader reader) { | ||
List<Function<IOSignalPiece<List<Double>>, Double>> rawList = | ||
reader.lines().map(SimpleSignalMapper::lineParse).collect(Collectors.toList()); | ||
|
||
return new SimpleSignalMapper(rawList); | ||
} | ||
|
||
static Function<IOSignalPiece<List<Double>>, Double> lineParse(String line) { | ||
net.maswag.SignalMapperVisitor<Function<IOSignalPiece<List<Double>>, Double>> visitor = new SignalMapperVisitorImpl(); | ||
return parseSignalMapperImpl(line, visitor); | ||
} | ||
|
||
private static Function<IOSignalPiece<List<Double>>, Double> parseSignalMapperImpl(String line, net.maswag.SignalMapperVisitor<Function<IOSignalPiece<List<Double>>, Double>> visitor) { | ||
CharStream stream = CharStreams.fromString(line); | ||
net.maswag.SignalMapperLexer lexer = new net.maswag.SignalMapperLexer(stream); | ||
CommonTokenStream tokens = new CommonTokenStream(lexer); | ||
net.maswag.SignalMapperParser parser = new net.maswag.SignalMapperParser(tokens); | ||
ParseTree tree = parser.expr(); | ||
return visitor.visit(tree); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
core/src/test/java/net/maswag/ExtendedSignalMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.maswag; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import static java.lang.Math.abs; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class ExtendedSignalMapperTest { | ||
SignalMapper sigMap; | ||
List<Double> concreteSignal; | ||
List<List<Double>> previousValues; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
concreteSignal = new ArrayList<>(); | ||
concreteSignal.add(2.0); | ||
concreteSignal.add(-4.2); | ||
concreteSignal.add(0.4); | ||
previousValues = new ArrayList<>(); | ||
previousValues.add(Arrays.asList(1.0, 2.0, 3.0)); | ||
previousValues.add(Arrays.asList(4.0, 5.0, 6.0)); | ||
} | ||
|
||
@Test | ||
void parse() throws IOException { | ||
String sigMapContent = "previous_max_output(2)\n" + "previous_min_output(2)"; | ||
BufferedReader reader = new BufferedReader(new StringReader(sigMapContent)); | ||
sigMap = ExtendedSignalMapper.parse(reader); | ||
assertEquals(2, sigMap.size()); | ||
assertEquals(Math.max(3.0, 6.0), sigMap.apply(0, | ||
new ExtendedIOSignalPiece<>(Collections.emptyList(), concreteSignal, previousValues))); | ||
assertEquals(Math.min(3.0, 6.0), sigMap.apply(1, | ||
new ExtendedIOSignalPiece<>(Collections.emptyList(), concreteSignal, previousValues))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.