mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-24 14:38:45 +00:00
bug4134_2: Added tests for ColorMapper and ValueRangeFlexibleBoundaries.
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
package com.sap.sailing.gwt.ui.test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import com.sap.sailing.gwt.ui.simulator.streamlets.ColorMapper;
|
||||
import com.sap.sailing.gwt.ui.simulator.streamlets.ValueRangeFlexibleBoundaries;
|
||||
|
||||
public class ColorMapperTest {
|
||||
ValueRangeFlexibleBoundaries valueRange = new ValueRangeFlexibleBoundaries(-5.0, 5.0, 0.0);
|
||||
ColorMapper colorMapperTestColored = new ColorMapper(valueRange, false);
|
||||
ColorMapper colorMapperTestGrey = new ColorMapper(valueRange, true);
|
||||
double testValue1 = -5.0;
|
||||
String expectedResult1colored = "hsl(240, 100%, 50%)";
|
||||
String expectedResult1grey = "rgba(255,255,255,0.0)";
|
||||
double testValue2 = 5.0;
|
||||
String expectedResult2colored = "hsl(0, 100%, 50%)";
|
||||
String expectedResult2grey = "rgba(255,255,255,1.0)";
|
||||
@Test
|
||||
public void testGetColor() {
|
||||
assertEquals(expectedResult1colored, colorMapperTestColored.getColor(testValue1));
|
||||
assertEquals(expectedResult1grey, colorMapperTestGrey.getColor(testValue1));
|
||||
assertEquals(expectedResult2colored, colorMapperTestColored.getColor(testValue2));
|
||||
assertEquals(expectedResult2grey, colorMapperTestGrey.getColor(testValue2));
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.sap.sailing.gwt.ui.test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import com.sap.sailing.gwt.ui.simulator.streamlets.ValueRangeFlexibleBoundaries;
|
||||
|
||||
public class ValueRangeFlexibleBoundariesTest {
|
||||
//Create new valueRange, boundaries should be [-6,-4] and [4,6].
|
||||
ValueRangeFlexibleBoundaries valueRange = new ValueRangeFlexibleBoundaries(-5.0, 5.0, 0.10);
|
||||
Double minLeft = -6.0;
|
||||
Double maxRight = 6.0;
|
||||
@Test
|
||||
public void testCheckIfValueIsInRightBoundaryRangeAndUpdateIfNecessary() {
|
||||
//update left border to 0.0, that means boundaries now should be [-0.5,0.5] and [4.5,5.5]
|
||||
valueRange.checkIfValueIsInLeftBoundaryRangeAndUpdateIfNecessary(0.0);
|
||||
Double newMinLeft = -0.5;
|
||||
Double newMaxRight = 5.5;
|
||||
assertEquals(newMinLeft, (Double) valueRange.getMinLeft());
|
||||
assertEquals(newMaxRight, (Double) valueRange.getMaxRight());
|
||||
}
|
||||
@Test
|
||||
public void testCheckIfValueIsInLeftBoundaryRangeAndUpdateIfNecessary() {
|
||||
//update right border to 20, that means the boundaries now should be [-7.5,-2.5] and [17.5,22.5]
|
||||
valueRange.checkIfValueIsInRightBoundaryRangeAndUpdateIfNecessary(20.0);
|
||||
Double newMaxRight = 22.5;
|
||||
Double newMinLeft = -7.5;
|
||||
assertEquals(newMaxRight, (Double) valueRange.getMaxRight());
|
||||
assertEquals(newMinLeft, (Double) valueRange.getMinLeft());
|
||||
}
|
||||
@Test
|
||||
public void testGetMinLeft() {
|
||||
assertEquals(minLeft, (Double) valueRange.getMinLeft());
|
||||
}
|
||||
@Test
|
||||
public void testGetMaxRight() {
|
||||
assertEquals(maxRight, (Double) valueRange.getMaxRight());
|
||||
}
|
||||
}
|
||||
+10
-11
@@ -4,14 +4,14 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class defines if a given value is within boundaries that are flexible by a given halfBoundaryWidth. The halfBoundaryWidth is
|
||||
* This class defines if a given extremal value is within boundaries that are flexible by a given halfBoundaryWidth. The halfBoundaryWidth is
|
||||
* defined by a percentage of the difference between max and min of a value range. It needs four types of boundaries:
|
||||
* a) minLeft
|
||||
* b) maxLeft
|
||||
* c) minRight
|
||||
* d) maxRight
|
||||
* (a)<--value->(b)..........(c)<--value->(d)
|
||||
* If a value is not within the left or the right boundaries the boundaries should be adjusted in a way that the value will fit in the
|
||||
* (a)<--minValue->(b)..........(c)<--maxValue->(d)
|
||||
* If an extremal value is not within the left or the right boundaries the boundaries should be adjusted in a way that the value will fit in the
|
||||
* one or the other. Also there should be the possibility to add listeners that will notify on a boundary change.
|
||||
*
|
||||
* A ValueRangeFlexibleBoundaries needs an initialMin, a initialMax and a percentage that indicates the width of the value range
|
||||
@@ -44,19 +44,18 @@ public class ValueRangeFlexibleBoundaries {
|
||||
maxLeft = min + halfBoundaryWidth;
|
||||
minRight = max - halfBoundaryWidth;
|
||||
maxRight = max + halfBoundaryWidth;
|
||||
notifyListeners();
|
||||
}
|
||||
public void checkIfValueIsInRightBoundaryRangeAndUpdateIfNecessary(double value) {
|
||||
if (!isValueInRightRange(value)) {
|
||||
max = value;
|
||||
public void checkIfValueIsInRightBoundaryRangeAndUpdateIfNecessary(double maxValue) {
|
||||
if (!isValueInRightRange(maxValue)) {
|
||||
max = maxValue;
|
||||
update();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
public void checkIfValueIsInLeftBoundaryRangeAndUpdateIfNecessary(double value) {
|
||||
if (!isValueInLeftRange(value)) {
|
||||
min = value;
|
||||
public void checkIfValueIsInLeftBoundaryRangeAndUpdateIfNecessary(double minValue) {
|
||||
if (!isValueInLeftRange(minValue)) {
|
||||
min = minValue;
|
||||
update();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
private boolean isValueInLeftRange(double value) {
|
||||
|
||||
Reference in New Issue
Block a user