Skip to content

Improve test writing experiences for devs #502

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

Merged
merged 4 commits into from
Jan 11, 2020

Conversation

antfu
Copy link
Member

@antfu antfu commented Jan 7, 2020

Refer to: #487

Changes

  • Make hanzi2num more clear and sperate num2hanzi and hanzi2num into different groups.
  • Utils for stdlib testing.
  • Stubs for stdlib.calendar.test.js and stdlib.math.test.js, should be fulfilled in the future.
  • Set timezone to UTC for calendar testing

The stdlib.calender.test.js currently looks like this:

const { createTestUtil } = require("./utils");

const { expectOutput } = createTestUtil({
  prefix: "吾嘗觀「「曆法」」之書。",
  suffix: "書之"
});

describe("stdlib", () => {
  describe("calendar", () => {
    it("言彼之時刻", () => {
      expectOutput(
        "方悟「言彼之時刻」之義。施「言彼之時刻」於四千七百一十四",
        "丑初一刻三分三十四秒"
      );
    });

    it("言彼之日時", () => {
      expectOutput(
        "方悟「言彼之日時」之義。施「言彼之日時」於四千七百一十四",
        "西元一九六九年己酉年十一月二十四日辛巳日丑初一刻三分三十四秒"
      );
    });
  });
});

@statementreply
Copy link
Contributor

I'm wondering whether it is possible to implement batch random testing for the math library. Maybe something like

const 算經 = compileLibrary("算經");

for (let i = 0; i < 10000; i++) {
  const x = Math.random() * Math.exp((Math.random() * 2 - 1) * 720);
  const jsResult = Math.log(x);
  const wyResult = 算經.對數(x);
  assert.ok(approxEqual(wyResult, jsResult, Number.EPSILON * 2, 0));
}

@antfu
Copy link
Member Author

antfu commented Jan 7, 2020

@statementreply I think it's possible. But I am not very sure if it's a good practice since the test will be unstable. Or we can use some seed-able random approach for that. I will do more research about random testing, please stay tuned.

And I like the compileLibrary idea! Will try to implement something like that.

Thanks!

@statementreply
Copy link
Contributor

statementreply commented Jan 7, 2020

@antfu I'm thinking about doing random testing on math lib locally. Maybe it's not a good idea for the workflow.

Edit: I just realized that I could write the random testing in wenyan (with hacks) if it's going to run locally :/

@antfu antfu requested a review from LingDong- January 10, 2020 09:47
Copy link
Member

@LingDong- LingDong- left a comment

Choose a reason for hiding this comment

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

L👍TM, feel free to merge :D

@antfu
Copy link
Member Author

antfu commented Jan 11, 2020

Merging now. If anyone comes up with better ideas, feel free to raise up!

@antfu antfu merged commit 1c0ab06 into wenyan-lang:master Jan 11, 2020
LingDong- pushed a commit that referenced this pull request Jan 20, 2020
Improve test writing experiences for devs
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.

3 participants