From 2b404ba8c82f2c62c215a7d6c4905c522fa02f8b Mon Sep 17 00:00:00 2001 From: Miroslav Batchkarov Date: Thu, 3 Jul 2014 22:55:58 +0100 Subject: [PATCH] Fixed problem with degree distribution chart. It was was not getting reset when the graph was updated. The issue only affected the visualisation- the underlying calculations are correct (as illustrated by the newly added unit test) Closes #44. --- src/main/java/controller/Stats.java | 1 + src/test/java/controller/StatsTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/controller/Stats.java b/src/main/java/controller/Stats.java index 36081b9..694f63e 100644 --- a/src/main/java/controller/Stats.java +++ b/src/main/java/controller/Stats.java @@ -530,6 +530,7 @@ public void updateDegreeDistributionChartData(boolean cumulative) { } else { buckets = getCumulativeDegreeDistribution(); } + this.degreeDistXYSeries.clear(); for (int i = 0; i < buckets.length; i++) { if (buckets[i] > 0) { if (buckets[i] > 0) { diff --git a/src/test/java/controller/StatsTest.java b/src/test/java/controller/StatsTest.java index 2c5eb85..a54300e 100644 --- a/src/test/java/controller/StatsTest.java +++ b/src/test/java/controller/StatsTest.java @@ -121,4 +121,16 @@ public void testGetAvgDegree() throws Exception { glass.addEdge(e(4), v(1), v(3)); assertEquals(2.5, glassStats.getAvgDegree(), 0.01); } + + @Test + public void testGetDegreDistribution(){ + + Stats s = new Stats(triangle); + assertArrayEquals(s.getDegreeDistribution(), + new int[]{0, 0, 3}); // three vertices of degree 2 + + s = new Stats(glass); + assertArrayEquals(s.getDegreeDistribution(), + new int[]{0, 1, 2, 1}); + } }