diff options
author | Size43 | 2015-05-19 16:38:27 +0200 |
---|---|---|
committer | Size43 | 2015-05-19 16:38:27 +0200 |
commit | f6bf94720690fc4594caad1b898a39f883191b8d (patch) | |
tree | 21c15b4808efbb8e8fb4e21fb51990884f0944be /app/src/androidTest | |
parent | Merge branch 'master' of https://github.com/camilstaps/RSSin (diff) | |
parent | FeedLoader fixes (diff) |
NN JUnit tests + fix
Diffstat (limited to 'app/src/androidTest')
-rwxr-xr-x | app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java | 66 | ||||
-rwxr-xr-x | app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java | 133 |
2 files changed, 199 insertions, 0 deletions
diff --git a/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java new file mode 100755 index 0000000..a2d59ee --- /dev/null +++ b/app/src/androidTest/java/org/rssin/neurons/FeedSorterTest.java @@ -0,0 +1,66 @@ +package org.rssin.neurons;
+
+import android.util.Log;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.rssin.rss.FeedItem;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+public class FeedSorterTest extends TestCase {
+
+ public void testFeedback() throws Exception {
+ Log.d("FeedSorterTest", "Dit is een test");
+ Assert.assertTrue(true);
+ }
+
+ public void testSortItems() throws Exception {
+ List<String> gameList = new ArrayList<>();
+ gameList.add("Games");
+ List<String> sportList = new ArrayList<>();
+ sportList.add("Sport");
+
+ FeedItem[] likedItems = new FeedItem[]
+ {
+ new FeedItem("", new Date(), "TITEL", "DESCRIPTION", "", "Randy", gameList, "", "", ""),
+ };
+
+ FeedItem[] dislikedItems = new FeedItem[]
+ {
+ new FeedItem("", new Date(), "TITEL", "DESCRIPTION", "", "Randy", sportList, "", "", ""),
+ };
+
+ FeedSorter s = new FeedSorter();
+
+ //I like games & I hate sports
+ for(int i = 0; i < 100; i++)
+ {
+ for(FeedItem item : likedItems)
+ {
+ s.feedback(item, Feedback.Like);
+ }
+
+ for(FeedItem item : dislikedItems)
+ {
+ s.feedback(item, Feedback.Dislike);
+ }
+ }
+
+ FeedItem sportsItem = new FeedItem("", new Date(2014, 1, 1, 1, 2, 1), "SPORT ARTICLE", "DESCRIPTION", "", "Randy", sportList, "", "", "");
+ FeedItem gamesItem = new FeedItem("", new Date(2014, 1, 1, 1, 1, 1), "GAME ARTICLE", "DESCRIPTION", "", "Randy", gameList, "", "", "");
+
+ List<FeedItem> testItems = new LinkedList<>();
+ testItems.add(sportsItem);
+ testItems.add(gamesItem);
+
+ List<FeedItem> sortedItems = s.sortItems(testItems);
+ Assert.assertEquals(sortedItems.get(0), gamesItem);
+ Assert.assertEquals(sortedItems.get(1), sportsItem);
+ }
+}
\ No newline at end of file diff --git a/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java b/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java new file mode 100755 index 0000000..b0f6eea --- /dev/null +++ b/app/src/androidTest/java/org/rssin/neurons/NeuralNetworkTest.java @@ -0,0 +1,133 @@ +package org.rssin.neurons;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class NeuralNetworkTest extends TestCase {
+
+ public void testAnd() throws Exception {
+ MultiNeuralNetwork nn = new MultiNeuralNetwork(10, 2);
+ nn.addInput();
+ nn.addInput();
+ nn.addInput();
+
+ //Simple AND
+ for (int i = 0; i < 100; i++)
+ {
+ PredictionInterface p1 = nn.computeOutput(new double[] {
+ 1,
+ -1,
+ -1,
+ });
+ p1.learn(-1);
+
+ PredictionInterface p2 = nn.computeOutput(new double[] {
+ 1,
+ -1,
+ 1,
+ });
+ p2.learn(-1);
+
+ PredictionInterface p3 = nn.computeOutput(new double[] {
+ 1,
+ 1,
+ -1,
+ });
+ p3.learn(-1);
+
+ PredictionInterface p4 = nn.computeOutput(new double[] {
+ 1,
+ 1,
+ 1,
+ });
+ p4.learn(1);
+ }
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ -1,
+ -1,
+ }).getOutput() < 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ 1,
+ -1,
+ }).getOutput() < 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ -1,
+ 1,
+ }).getOutput() < 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ 1,
+ 1,
+ }).getOutput() > 0);
+ }
+
+ public void testXor() throws Exception {
+ MultiNeuralNetwork nn = new MultiNeuralNetwork(10, 2);
+ nn.addInput();
+ nn.addInput();
+ nn.addInput();
+
+ //Simple AND
+ for (int i = 0; i < 100; i++)
+ {
+ PredictionInterface p1 = nn.computeOutput(new double[] {
+ 1,
+ -1,
+ -1,
+ });
+ p1.learn(-1);
+
+ PredictionInterface p2 = nn.computeOutput(new double[] {
+ 1,
+ -1,
+ 1,
+ });
+ p2.learn(1);
+
+ PredictionInterface p3 = nn.computeOutput(new double[] {
+ 1,
+ 1,
+ -1,
+ });
+ p3.learn(1);
+
+ PredictionInterface p4 = nn.computeOutput(new double[] {
+ 1,
+ 1,
+ 1,
+ });
+ p4.learn(-1);
+ }
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ -1,
+ -1,
+ }).getOutput() < 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ 1,
+ -1,
+ }).getOutput() > 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ -1,
+ 1,
+ }).getOutput() > 0);
+
+ Assert.assertTrue(nn.computeOutput(new double[] {
+ 1,
+ 1,
+ 1,
+ }).getOutput() < 0);
+ }
+}
\ No newline at end of file |