Example: use incineration to achieve more balanced reweighting

This commit is contained in:
Ladd Hoffman 2023-03-14 20:53:19 -05:00
parent 5988950857
commit 0a8b170115
4 changed files with 76 additions and 0 deletions

View File

@ -23,6 +23,7 @@
<li><a href="./tests/forum6.test.html">Initially zero-valued posts later receive citations</a></li>
<li><a href="./tests/forum7.test.html">Negatively cite a zero-valued post</a></li>
<li><a href="./tests/forum8.test.html">Incinerate reputation</a></li>
<li><a href="./tests/forum9.test.html">Use incineration to achieve more balanced reweighting</a></li>
</ol>
</ul>
<ul>

View File

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

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<head>
<title>Forum test 9</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/forum9.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
});
chai.should();
</script>

View File

@ -0,0 +1,48 @@
import { INCINERATOR_ADDRESS, mochaRun } from '../../../util.js';
import { ForumTest } from './forum.test-util.js';
describe('Forum', function tests() {
this.timeout(0);
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Use incineration to achieve more balanced reweighting', 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], 0);
forum.getPost(posts[0]).value.should.equal(10);
forum.getPost(posts[1]).value.should.equal(0);
});
it('Post3 transfers reputation from Post1 to Post2', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[0], weight: -1 },
{ postId: posts[1], weight: 0.5 },
{ postId: INCINERATOR_ADDRESS, weight: 0.5 },
]);
forum.getPost(posts[0]).value.should.equal(0);
forum.getPost(posts[1]).value.should.equal(10);
forum.getPost(posts[2]).value.should.equal(0);
});
});
});
mochaRun();