Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Testing for Discojs #697

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Basic Testing for Discojs #697

wants to merge 8 commits into from

Conversation

josh-freeman
Copy link
Collaborator

No description provided.

… equals are useless boilerplate for a short function (a variable should only be declared if it is used at least twice, except in very few exceptions that need excplicit justification
Copy link
Collaborator

@tharvik tharvik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution! some stuff to iron out, I hope that the remarks will help.

you didn't explicitly ask for a review but your PR wasn't in draft so I though I'll take a look
also, the CI failed with some lint error, you might want to look into it.

btw, the branch name is not following our guidelines, its format is $issue-$description-in-very-few-workd-$username

Comment on lines 33 to 40
it("model correctly initialized", async () => {
const aggregator = new Aggregator();

const model = mock(Model);

aggregator.setModel(instance(model));
expect(aggregator.model).to.equal(instance(model));
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, no need to test for that, aggregator would need to be redone at some point and avoiding to have any reference to the task or the model will be the first thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. It's the first time I work on GitHub with PRs that are not made by cloning for a PR. Should I make a new branch from this branch for the PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I follow you: this is already a PR, you can added changes by pushing new commits to the same branch ("test_components") and it'll show up here.

@@ -1,6 +1,6 @@
import { expect } from "chai";
import { Map, Range, Set } from "immutable";

import { mock, instance, when, anything } from 'ts-mockito';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, discojs is still using mocha/chai but if we want new features not present in theses, we will rather move to vitest (already used in the webapp & discojs-node) which provides mocking, parallel testing, good typescript support, …
that said, after the other comments, I don't think you'll even need "ts-mockito" anymore

@@ -20,10 +20,53 @@ AGGREGATORS.forEach(([name, Aggregator]) =>
describe(`${name} implements Aggregator contract`, () => {
it("starts at round zero", () => {
const aggregator = new Aggregator();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not needed (and is being shown as very red in my git diff).

we don't enforce a formatter yet but I'm all for slowly moving to prettier (that is, when you add changes, prettify it around, but not the whole file if you only changed a line). I'm hopeful that the transition will be smoother this way.

expect(aggregator.isFull());
});

it("is not full when created with more than no nodes and empty", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("is not full when created with more than no nodes and empty", () => {
it("is empty when without contributions", () => {




it("is full when enough contributions", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("is full when enough contributions", () => {
it("is full with enough contributions", () => {

Comment on lines +54 to +55


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much whitespaces

Suggested change

expect(aggregator.round).to.equal(1);
});

it("does not move forward with not enough contributions", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double negation are hard on my brain. it also feels as a duplicate of the previous one. you can merge the two and check that it didn't advance with only two clients contributions but does with three.

expect(aggregator.round).to.equal(0);
});

it("Adding at the wrong round does not count", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reads more nicely. also, you can keep the test itself smaller by not having three clients but only one. less code == faster to understand => less bug.

Suggested change
it("Adding at the wrong round does not count", () => {
it("drops contributions for futur rounds", () => {

@@ -11,7 +11,8 @@
"webapp"
],
"dependencies": {
"immutable": "4"
"immutable": "4",
"ts-mockito": "^2.6.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the root package.json is hardly ever changed, especially for dev deps used in a single package. I use it for syncing version of dependencies that are needed across many packages.
please modify discojs/package.json if you want to add a package for discojs. (which you probably don't need as stated previously)

Comment on lines +37 to +68
it('avg of weights with no operands throws an error', () => {
assert.throws(() => aggregation.avg([]))
})

it('sum of weights with no operands throws an error', () => {
assert.throws(() => aggregation.sum([]))
})

it('diff of weights with no operands throws an error', () => {
assert.throws(() => aggregation.diff([]))
})

it('avg of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.avg([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})

it('sum of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.sum([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})

it('diff of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.diff([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bench test, you can simplify it by using a Set(…).forEach((op) => …)

while at it, should it fail? an addition without value can be zero, a multiplication can be one; why is this test needed?

Suggested change
it('avg of weights with no operands throws an error', () => {
assert.throws(() => aggregation.avg([]))
})
it('sum of weights with no operands throws an error', () => {
assert.throws(() => aggregation.sum([]))
})
it('diff of weights with no operands throws an error', () => {
assert.throws(() => aggregation.diff([]))
})
it('avg of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.avg([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})
it('sum of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.sum([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})
it('diff of weights with different dimensions throws an error', () => {
assert.throws(() => aggregation.diff([
[[3, -4], [9]],
[[2, 13, 4], [0, 1]]
]))
})
Set.of(aggregation.avg, aggregation.sum, aggregation.diff).forEach((op) => {
it(`${op.name} of weights with no operands throws`, () =>
expect(() => op([])).to.throw());
it(`${op.name} of weights with different dimensions throws`, () =>
expect(() => op([[[1, 2]], [[3, 4, 5]]])).to.throw());
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants