Re-implemented GraphTest.

This commit is contained in:
Rsl1122 2018-01-27 13:16:45 +02:00
parent 3d6472343c
commit 1de2723662
2 changed files with 43 additions and 31 deletions

View File

@ -15,8 +15,7 @@ import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
/**
* This manage subcommand is used to swap to a different database and reload the
* plugin if the connection to the new database can be established.
* This manage SubCommand is used to request settings from Bungee so that connection can be established.
*
* @author Rsl1122
* @since 2.3.0

View File

@ -4,54 +4,34 @@
*/
package com.djrapitops.plan.ui.graphs;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.utilities.analysis.Point;
import com.djrapitops.plan.utilities.html.graphs.line.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import test.utilities.RandomData;
import test.utilities.TestInit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import static org.junit.Assert.assertTrue;
/**
* @author Fuzzlemann
* Tests various Graphs.
*
* @author Rsl1122
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({JavaPlugin.class})
public class GraphTest {
private final List<TPS> tpsList = new ArrayList<>();
private final List<Session> sessionList = new ArrayList<>();
private final Map<String, Integer> geoList = new HashMap<>();
private final WorldTimes worldTimes = new WorldTimes("WORLD", "SURVIVAL");
private List<Point> points = new ArrayList<>();
@Before
public void setUp() throws Exception {
TestInit t = TestInit.init();
public void setUp() {
for (int i = 0; i < 10; i++) {
tpsList.add(new TPS(i, i, i, i, i, i, i));
sessionList.add(new Session(i, (long) i, (long) i, i, i));
geoList.put(String.valueOf(i), i);
}
points = RandomData.randomPoints();
}
@Test
@Ignore("Test should use Stack instead")
public void testLineGraphsForBracketErrors() {
AbstractLineGraph[] graphs = new AbstractLineGraph[]{
new CPUGraph(tpsList),
@ -63,8 +43,41 @@ public class GraphTest {
};
for (AbstractLineGraph graph : graphs) {
System.out.print("Bracket Test: " + graph.getClass().getSimpleName() + " | ");
String series = graph.toHighChartsSeries();
// TODO Use Stack instead.
System.out.println(series);
char[] chars = series.toCharArray();
assertBracketMatch(chars);
}
}
private void assertBracketMatch(char[] chars) {
Stack<Character> bracketStack = new Stack<>();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
switch (c) {
case '{':
case '[':
case '(':
bracketStack.push(c);
break;
case ')':
Character pop = bracketStack.pop();
assertTrue("Bracket mismatch at char: " + i + " Expected (, got " + pop, '(' == pop);
break;
case ']':
Character pop1 = bracketStack.pop();
assertTrue("Bracket mismatch at char: " + i + " Expected [, got " + pop1, '[' == pop1);
break;
case '}':
Character pop2 = bracketStack.pop();
assertTrue("Bracket mismatch at char: " + i + " Expected {, got " + pop2, '{' == pop2);
break;
default:
break;
}
}
}
}