From 721718ac1341f056404716a08afc082432598080 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sun, 29 Jan 2023 18:51:24 -0600 Subject: [PATCH] Add failing test for power redistribution via subsequent support --- forum-network/src/index.html | 7 +-- forum-network/src/tests/forum4.test.html | 27 ++++++++++ .../src/tests/scripts/forum4.test.js | 53 +++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 forum-network/src/tests/forum4.test.html create mode 100644 forum-network/src/tests/scripts/forum4.test.js diff --git a/forum-network/src/index.html b/forum-network/src/index.html index 947bda4..2cc69ea 100644 --- a/forum-network/src/index.html +++ b/forum-network/src/index.html @@ -12,9 +12,10 @@
  • Forum
  • diff --git a/forum-network/src/tests/forum4.test.html b/forum-network/src/tests/forum4.test.html new file mode 100644 index 0000000..7684f26 --- /dev/null +++ b/forum-network/src/tests/forum4.test.html @@ -0,0 +1,27 @@ + + + Forum test 4 + + + + + +
    +
    + + + + + + + diff --git a/forum-network/src/tests/scripts/forum4.test.js b/forum-network/src/tests/scripts/forum4.test.js new file mode 100644 index 0000000..fbd56da --- /dev/null +++ b/forum-network/src/tests/scripts/forum4.test.js @@ -0,0 +1,53 @@ +import { ForumTest } from './forum.test-util.js'; + +describe('Forum', () => { + const forumTest = new ForumTest(); + + before(async () => { + await forumTest.setup(); + }); + + context('Redistribute power through subsequent support', async () => { + it('Post1', async () => { + const { forum, experts, posts } = forumTest; + await forumTest.addPost(experts[0], 10); + forum.getPost(posts[0]).value.should.equal(10); + }); + + it('Post2', async () => { + const { forum, experts, posts } = forumTest; + await forumTest.addPost(experts[0], 10); + forum.getPost(posts[0]).value.should.equal(10); + forum.getPost(posts[1]).value.should.equal(10); + }); + + it('Post3 cites Post2 and negatively cites Post1', async () => { + const { forum, experts, posts } = forumTest; + await forumTest.addPost(experts[0], 0, [ + { postId: posts[0], weight: -0.5 }, + { postId: posts[1], weight: 0.5 }, + ]); + forum.getPost(posts[0]).value.should.equal(10); + forum.getPost(posts[1]).value.should.equal(10); + forum.getPost(posts[2]).value.should.equal(0); + }); + + it('Post4 cites Post3 to strengthen its effect', async () => { + const { forum, experts, posts } = forumTest; + await forumTest.addPost(experts[0], 20, [ + { postId: posts[2], weight: 1 }, + ]); + forum.getPost(posts[0]).value.should.equal(0); + forum.getPost(posts[1]).value.should.equal(20); + forum.getPost(posts[2]).value.should.equal(20); + forum.getPost(posts[3]).value.should.equal(0); + }); + }); +}); + +// await addPost(experts[0], 10); +// await addPost(experts[0], 10, [{ postId: posts[3], weight: -1 }]); +// await addPost(experts[0], 10, [{ postId: posts[4], weight: -1 }]); + +// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); +// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);