Add forum test 6

This commit is contained in:
Ladd Hoffman 2023-02-13 10:54:28 -06:00
parent 602ce75871
commit e7ef21527a
4 changed files with 123 additions and 1 deletions

View File

@ -20,6 +20,7 @@
<li><a href="./tests/forum3.test.html">Redistribute power</a></li>
<li><a href="./tests/forum4.test.html">Redistribute power through subsequent support</a></li>
<li><a href="./tests/forum5.test.html">Destroy a post after it has received positive citations</a></li>
<li><a href="./tests/forum6.test.html">Reversal of power redistribution</li>
</ol>
</ul>
<ul>

View File

@ -29,6 +29,7 @@
<script type="module" src="./scripts/forum/forum3.test.js"></script>
<script type="module" src="./scripts/forum/forum4.test.js"></script>
<script type="module" src="./scripts/forum/forum5.test.js"></script>
<script type="module" src="./scripts/forum/forum6.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<head>
<title>Forum test 6</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
<link type="text/css" rel="stylesheet" href="../index.css" />
</head>
<body>
<h2><a href="../">DGF Tests</a></h2>
<div id="mocha"></div>
<div id="scene"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js"
integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/chai/chai.js"></script>
<script type="module" src="./scripts/forum/forum6.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
});
mocha.checkLeaks();
chai.should();
</script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -0,0 +1,88 @@
import { ForumTest } from './forum.test-util.js';
describe('Forum', () => {
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Reversal of power redistribution', async () => {
let forum;
let experts;
let posts;
before(() => {
forum = forumTest.forum;
experts = forumTest.experts;
posts = forumTest.posts;
});
it('Post1', async () => {
await forumTest.addPost(experts[0], 10);
forum.getPost(posts[0]).value.should.equal(10);
});
it('Post2', async () => {
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 () => {
await forumTest.addPost(experts[0], 0, [
{ postId: posts[0], weight: -1 },
{ postId: posts[1], weight: 1 },
]);
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 () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[2], weight: 1 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(30);
forum.getPost(posts[2]).value.should.equal(0);
forum.getPost(posts[3]).value.should.equal(0);
});
it('Post5 cites Post3 to strengthen its effect', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[2], weight: 1 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(40);
forum.getPost(posts[2]).value.should.equal(0);
forum.getPost(posts[3]).value.should.equal(0);
forum.getPost(posts[4]).value.should.equal(0);
});
it('Post6 cites Post3 negatively', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[2], weight: -1 },
]);
forum.getPost(posts[0]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(20);
forum.getPost(posts[2]).value.should.equal(0);
forum.getPost(posts[3]).value.should.equal(0);
forum.getPost(posts[4]).value.should.equal(0);
forum.getPost(posts[5]).value.should.equal(20);
});
it('Post7 cites Post3 negatively', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[2], weight: -1 },
]);
forum.getPost(posts[0]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(10);
forum.getPost(posts[2]).value.should.equal(0);
forum.getPost(posts[3]).value.should.equal(0);
forum.getPost(posts[4]).value.should.equal(0);
forum.getPost(posts[5]).value.should.equal(20);
forum.getPost(posts[6]).value.should.equal(20);
});
});
});