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

Added final changes to scales.h and testing for scales.h #337

Merged
merged 52 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
19ca52d
added SequentialOrDivergingScale class, cleaned up tests
Oliver-BE Jun 25, 2020
a0e2a0e
added getters, organized new scales
Oliver-BE Jun 25, 2020
4bd40fa
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jun 29, 2020
8250ac4
added push_map_to_javascript functionality
Oliver-BE Jun 29, 2020
ba9c6ae
made base class constructors protected
Oliver-BE Jun 29, 2020
3d69467
added template specialization to ApplyScale
Oliver-BE Jun 30, 2020
f6b7290
fixes to pass_map_to_javascript
Oliver-BE Jun 30, 2020
832bc23
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jul 1, 2020
88f41a6
cleaned up pass_map_to_javascript
Oliver-BE Jul 1, 2020
2750f87
fixed apply scale date
Oliver-BE Jul 2, 2020
a4d0df5
fixed ApplyScale for Date input
Oliver-BE Jul 7, 2020
6e6106b
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jul 7, 2020
8864f62
created working scale tests and started testing linear scale
Oliver-BE Jul 7, 2020
ebc36ed
added working tests for linear and pow scale
Oliver-BE Jul 8, 2020
603eeae
added passing tests for sqrt, log, and symlog scales
Oliver-BE Jul 9, 2020
fb45fd4
added passing tests for identity scale and time scale. cleaned up som…
Oliver-BE Jul 10, 2020
bbfe82c
Add Dockerfile
mmore500 Jul 11, 2020
9dbe79a
Advertise Docker container on README.md
mmore500 Jul 11, 2020
335644c
Entrypoint should be path to script
mmore500 Jul 11, 2020
49da5b8
Fixup formatting
mmore500 Jul 11, 2020
ae4a9cf
Initialize git submodules for DockerHub
mmore500 Jul 11, 2020
9911efa
Try separating submodule init and update
mmore500 Jul 11, 2020
1bdd295
Try nuking and then reininitializing submodules
mmore500 Jul 11, 2020
712ac43
Escape #'s in scripts
mmore500 Jul 11, 2020
a036443
Separate submodule init, install test deps
mmore500 Jul 11, 2020
b22fb33
More selectively remove cached files
mmore500 Jul 11, 2020
9be97c4
Try a better way to clear submodules
mmore500 Jul 11, 2020
675028d
Try adding -f flag to update
mmore500 Jul 11, 2020
097cc95
Re-fix shebangs
mmore500 Jul 11, 2020
4356305
Remove mysterious set -e line
mmore500 Jul 11, 2020
3654f76
Add -f flag to submodule deinit
mmore500 Jul 11, 2020
7cdb2d4
Revert "Remove mysterious set -e line"
mmore500 Jul 11, 2020
7cf8c3b
Remove default command
mmore500 Jul 11, 2020
6142620
Fixup entrypoint
mmore500 Jul 11, 2020
d2070d7
Merge pull request #331 from devosoft/docker
mmore500 Jul 13, 2020
06249e2
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jul 13, 2020
40f3e4f
Merge branch 'master' into d3-wrapper-dev-oliver
Oliver-BE Jul 14, 2020
afe156e
Switch from ssh to https ref to origin
mmore500 Jul 14, 2020
1fbdfde
Fixup Dockerfile
mmore500 Jul 14, 2020
47e8875
added file that demonstrates core functionality of writing emscripten…
Oliver-BE Jul 14, 2020
cb29bcd
Merge pull request #332 from devosoft/mmore500-patch-docker
mmore500 Jul 14, 2020
81d5993
Install karma-firefox-launcher
mmore500 Jul 15, 2020
490f73e
Merge pull request #333 from devosoft/mmore500-dockerfile-windows
mmore500 Jul 15, 2020
2781fa7
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jul 15, 2020
de11e53
added blogpost rough draft file
Oliver-BE Jul 15, 2020
7f062b4
added remaining tests, fixed small bugs in scales.h
Oliver-BE Jul 21, 2020
e6f0de0
Merge branch 'master' into d3-wrapper-dev-oliver
Oliver-BE Jul 21, 2020
6be9019
fixed comments and spacing
Oliver-BE Jul 21, 2020
8b24450
removing file
Oliver-BE Jul 21, 2020
8d64538
removing enrichment.cc
Oliver-BE Jul 21, 2020
b6a48a0
Merge branch 'd3-wrapper' into d3-wrapper-dev-oliver
Oliver-BE Jul 21, 2020
98e7075
removing test_scales.cc
Oliver-BE Jul 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added passing tests for sqrt, log, and symlog scales
  • Loading branch information
Oliver-BE committed Jul 9, 2020
commit 603eeaedd42253781294df0ffe3468c9c5124a05
5 changes: 2 additions & 3 deletions source/web/d3/scales.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ namespace D3 {
}

// .unknown()
ContinuousScale & SetUnkown(double value) {
ContinuousScale & SetUnknown(double value) {
EM_ASM({
emp_d3.objects[$0].unknown($1);
}, this->id, value);
return *this;
}

ContinuousScale & SetUnkown(const std::string & value) {
ContinuousScale & SetUnknown(const std::string & value) {
EM_ASM({
emp_d3.objects[$0](UTF8ToString($1));
}, this->id, value.c_str());
Expand Down Expand Up @@ -346,7 +346,6 @@ namespace D3 {
}
};


// scaleLog
class LogScale : public ContinuousScale {
protected:
Expand Down
250 changes: 249 additions & 1 deletion tests/web/d3/scales.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,228 @@ struct TestPowScale : emp::web::BaseTest {
}
};

struct TestSqrtScale : emp::web::BaseTest {
// a regular SqrtScale with domain and range as ints/doubles
D3::SqrtScale testSqrt1;
double testSqrt1_val1;
double testSqrt1_val2;
double testSqrt1_val3;

// a copy of the above testSqrt1 scale
// D3::SqrtScale testSqrtCopy;
double testSqrtCopy_val1;
double testSqrtCopy_val2;
double testSqrtCopy_val3;

TestSqrtScale() { Setup(); }

void Setup() {
testSqrt1.SetDomain(0, 2e9);
testSqrt1.SetRange(0, 300);
testSqrt1_val1 = testSqrt1.ApplyScale<double>(1.386e9);
testSqrt1_val2 = testSqrt1.ApplyScale<double>(127e6);
testSqrt1_val3 = testSqrt1.ApplyScale<double>(427e3);

D3::SqrtScale testSqrtCopy(testSqrt1);
testSqrtCopy_val1 = testSqrtCopy.ApplyScale<double>(1.386e9);
testSqrtCopy_val2 = testSqrtCopy.ApplyScale<double>(127e6);
testSqrtCopy_val3 = testSqrtCopy.ApplyScale<double>(427e3);
}

void Describe() override {
EM_ASM({
const testSqrt1_val1 = $0;
const testSqrt1_val2 = $1;
const testSqrt1_val3 = $2;
const testSqrtCopy_val1 = $3;
const testSqrtCopy_val2 = $4;
const testSqrtCopy_val3 = $5;

var population = d3.scaleSqrt()
.domain([0, 2e9])
.range([0, 300]);

var copyPopulation = population.copy();

describe("creating a sqrt scale", function() {
it("should apply the first scale correctly", function() {
chai.assert.equal(testSqrt1_val1, population(1.386e9)); // 249.73986465920893
chai.assert.equal(testSqrt1_val2, population(127e6)); // 75.59761901012492
chai.assert.equal(testSqrt1_val3, population(427e3)); // 4.383491758860737
});
it("copy the first scale correctly", function() {
chai.assert.equal(testSqrtCopy_val1, copyPopulation(1.386e9)); // 249.73986465920893
chai.assert.equal(testSqrtCopy_val2, copyPopulation(127e6)); // 75.59761901012492
chai.assert.equal(testSqrtCopy_val3, copyPopulation(427e3)); // 4.383491758860737
});
});
}, testSqrt1_val1, testSqrt1_val2, testSqrt1_val3, testSqrtCopy_val1, testSqrtCopy_val2, testSqrtCopy_val3);
}
};

struct TestLogScale : emp::web::BaseTest {
// a log scale with no explicit base set (default is 10)
D3::LogScale testLog1;
double testLog1_val1;
double testLog1_val2;
double testLog1_val3;

// a log scale with a base of 2
D3::LogScale testLog2;
double testLog2_val1;
double testLog2_val2;
double testLog2_val3;
double testLog2_Unclamped;
double testLog2_Clamped;

TestLogScale() { Setup(); }

void Setup() {
testLog1.SetDomain(10, 100000).SetRange(0, 700);
testLog1_val1 = testLog1.ApplyScale<double>(1000);
testLog1_val2 = testLog1.ApplyScale<double>(1234);
testLog1_val3 = testLog1.ApplyScale<double>(100000);

testLog2.SetBase(2);
testLog2.SetDomain(16, 1048576);
testLog2.SetRange(0, 700);
testLog2_val1 = testLog2.ApplyScale<double>(64);
testLog2_val2 = testLog2.ApplyScale<double>(1234);
testLog2_val3 = testLog2.ApplyScale<double>(1048576);
testLog2_Unclamped = testLog2.ApplyScale<double>(5000000);

// now clamp TestScale2 to test the SetClamp method
testLog2.SetClamp(true);
testLog2_Clamped = testLog2.ApplyScale<double>(5000000);
}

void Describe() override {
EM_ASM({
const testLog1_val1 = $0;
const testLog1_val2 = $1;
const testLog1_val3 = $2;
const testLog2_val1 = $3;
const testLog2_val2 = $4;
const testLog2_val3 = $5;
const testLog2_Unclamped = $6;
const testLog2_Clamped = $7;

var logScale = d3.scaleLog()
.domain([10, 100000])
.range([0, 700]);

var logScale2 = d3.scaleLog()
.base(2)
.domain([16, 1048576])
.range([0, 700]);

var logScale2_Clamped = d3.scaleLog()
.base(2)
.domain([16, 1048576])
.range([0, 700])
.clamp(true);

describe("creating a log scale", function() {
it("should apply the first scale correctly", function() {
chai.assert.equal(testLog1_val1, logScale(1000)); // 349.99999999999994
chai.assert.equal(testLog1_val2, logScale(1234)); // 365.980152947014
chai.assert.equal(testLog1_val3, logScale(100000)); // 700
});
it("should apply the second scale correctly", function() {
chai.assert.equal(testLog2_val1, logScale2(64)); // 87.49999999999999
chai.assert.equal(testLog2_val2, logScale2(1234)); // 274.2742922127871
chai.assert.equal(testLog2_val3, logScale2(1048576)); // 700
});
it("should enable clamping on the second scale correctly", function() {
chai.assert.equal(testLog2_Unclamped, logScale2(5000000)); // 798.5904790592547
chai.assert.equal(testLog2_Clamped, logScale2_Clamped(5000000)); // 700
});
});
}, testLog1_val1, testLog1_val2, testLog1_val3, testLog2_val1, testLog2_val2, testLog2_val3, testLog2_Unclamped, testLog2_Clamped);
}
};

struct TestSymlogScale : emp::web::BaseTest {
// a symlog scale with no explicit constant set (default is 1)
D3::SymlogScale testSymlog1;
double testSymlog1_val1;
double testSymlog1_val2;
double testSymlog1_val3;
double testSymlog1_val4;
double testSymlog1_val5;

// the same symlog scale but with a constant of 0.01
D3::SymlogScale testSymlog2;
double testSymlog2_val1;
double testSymlog2_val2;
double testSymlog2_val3;
double testSymlog2_val4;
double testSymlog2_val5;

TestSymlogScale() { Setup(); }

void Setup() {
testSymlog1.SetDomain(-100000, 100000);
testSymlog1.SetRange(-100, 100);
testSymlog1_val1 = testSymlog1.ApplyScale<double>(-80000);
testSymlog1_val2 = testSymlog1.ApplyScale<double>(-50);
testSymlog1_val3 = testSymlog1.ApplyScale<double>(1.5);
testSymlog1_val4 = testSymlog1.ApplyScale<double>(50);
testSymlog1_val5 = testSymlog1.ApplyScale<double>(80000);

testSymlog2.SetDomain(-100000, 100000);
testSymlog2.SetRange(-100, 100);
testSymlog2.SetConstant(0.01);
testSymlog2_val1 = testSymlog2.ApplyScale<double>(-80000);
testSymlog2_val2 = testSymlog2.ApplyScale<double>(-50);
testSymlog2_val3 = testSymlog2.ApplyScale<double>(1.5);
testSymlog2_val4 = testSymlog2.ApplyScale<double>(50);
testSymlog2_val5 = testSymlog2.ApplyScale<double>(80000);
}

void Describe() override {
EM_ASM({
const testSymlog1_val1 = $0;
const testSymlog1_val2 = $1;
const testSymlog1_val3 = $2;
const testSymlog1_val4 = $3;
const testSymlog1_val5 = $4;
const testSymlog2_val1 = $5;
const testSymlog2_val2 = $6;
const testSymlog2_val3 = $7;
const testSymlog2_val4 = $8;
const testSymlog2_val5 = $9;

var symlogScale1 = d3.scaleSymlog()
.domain([-100000, 100000])
.range([-100, 100]);

var symlogScale2 = d3.scaleSymlog()
.domain([-100000, 100000])
.range([-100, 100])
.constant(0.01);

describe("creating a symlog scale", function() {
it("should apply the first scale correctly", function() {
chai.assert.equal(testSymlog1_val1, symlogScale1(-80000)); // -98.06182313778929
chai.assert.equal(testSymlog1_val2, symlogScale1(-50)); // -34.15137385860061
chai.assert.equal(testSymlog1_val3, symlogScale1(1.5)); // 7.958793260555325
chai.assert.equal(testSymlog1_val4, symlogScale1(50)); // 34.15137385860061
chai.assert.equal(testSymlog1_val5, symlogScale1(80000)); // 98.06182313778928
});
it("should apply the second scale correctly", function() {
chai.assert.equal(testSymlog2_val1, symlogScale2(-80000)); // -98.61557140643649
chai.assert.equal(testSymlog2_val2, symlogScale2(-50)); // -52.843669022827925
chai.assert.equal(testSymlog2_val3, symlogScale2(1.5)); // 31.128241911062098
chai.assert.equal(testSymlog2_val4, symlogScale2(50)); // 52.843669022827925
chai.assert.equal(testSymlog2_val5, symlogScale2(80000)); // 98.61557140643649
});
});
}, testSymlog1_val1, testSymlog1_val2, testSymlog1_val3, testSymlog1_val4, testSymlog1_val5,
testSymlog2_val1, testSymlog2_val2, testSymlog2_val3, testSymlog2_val4, testSymlog2_val5);
}
};

emp::web::MochaTestRunner test_runner;

int main() {
Expand All @@ -241,10 +463,36 @@ int main() {

test_runner.AddTest<TestLinearScale>("LinearScale");
test_runner.AddTest<TestPowScale>("PowScale");
test_runner.AddTest<TestSqrtScale>("SqrtScale");
test_runner.AddTest<TestLogScale>("LogScale");
test_runner.AddTest<TestSymlogScale>("SymlogScale");

test_runner.OnBeforeEachTest([]() {
ResetD3Context();
});

test_runner.Run();
}
}

// struct TestSqrtScale : emp::web::BaseTest {
// D3::PowScale testSqrt1;

// TestSqrtScale() { Setup(); }

// void Setup() {
// testSqrt1.SetDomain();
// testSqrt1.SetRange();
// }

// void Describe() override {
// EM_ASM({
// describe("creating a pow scale", function() {
// it("should apply the first scale correctly", function() {
// chai.assert.equal(testPow1_val1, population(1.386e9)); // 249.73986465920893
// chai.assert.equal(testPow1_val2, population(127e6)); // 75.59761901012492
// chai.assert.equal(testPow1_val3, population(427e3)); // 4.383491758860737
// });
// });
// });
// }
// };