Browse Source

Added RunStatistics_AllGood

Piotr Czajkowski 2 years ago
parent
commit
a91331b65d
2 changed files with 27 additions and 1 deletions
  1. 1 1
      analyzeJSON/Statistics.cs
  2. 26 0
      analyzeJSONTests/StatisticsUnitTests.cs

+ 1 - 1
analyzeJSON/Statistics.cs

@@ -12,7 +12,7 @@ namespace analyzeJSON
 
         private static int CountWords(string text)
         {
-            var words = text.Split(" ");
+            var words = text.Split(new char[] { ' ', '\t', '\n' });
             return words.Count(x => !string.IsNullOrWhiteSpace(x));
         }
 

+ 26 - 0
analyzeJSONTests/StatisticsUnitTests.cs

@@ -0,0 +1,26 @@
+using Xunit;
+using analyzeJSON;
+using Newtonsoft.Json.Linq;
+
+namespace analyzeJSONTests
+{
+    public class StatisticsUnitTests
+    {
+        [Fact]
+        public void RunStatistics_AllGood()
+        {
+            dynamic token = new JObject();
+            token.one = "Lorem ipsum dolor";
+            token.two = "Lorem      ipsum dolor";
+            token.three = "Lorem\nipsum dolor";
+
+            var stats = new Statistics();
+            stats.RunStatistics(token.one);
+            stats.RunStatistics(token.two);
+            stats.RunStatistics(token.three);
+
+            Assert.Equal(3, stats.Result.NodeCounts.Count);
+            Assert.Equal(9, stats.Result.TotalWordCount);
+        }
+    }
+}