-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch from should to expect (#1163)
* switch from should to expect * fix build * install typescript * fix type test
- Loading branch information
1 parent
a2dbeb5
commit 22f2535
Showing
41 changed files
with
1,493 additions
and
1,554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
import { Jimp } from "@jimp/test-utils"; | ||
import expect from "@storybook/expect"; | ||
|
||
// Convert [0..1] float to a percent value with only one decimal. | ||
const pct = (n) => ((n * 1000) << 0) / 10; | ||
|
||
describe("compute color difference", () => { | ||
it("totally opaque (no alpha defined)", () => { | ||
Jimp.colorDiff( | ||
{ r: 255, g: 0, b: 0 }, | ||
{ r: 255, g: 0, b: 0 } | ||
).should.be.equal(0, "both red"); | ||
|
||
pct( | ||
Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 0, b: 0 }) | ||
).should.be.equal(33.3, "red x black"); | ||
|
||
pct( | ||
Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 0 }) | ||
).should.be.equal(66.6, "red x green"); | ||
|
||
Jimp.colorDiff( | ||
{ r: 255, g: 0, b: 0 }, | ||
{ r: 0, g: 255, b: 255 } | ||
).should.be.equal(1, "red x cyan"); | ||
|
||
Jimp.colorDiff( | ||
{ r: 0, g: 0, b: 0 }, | ||
{ r: 255, g: 255, b: 255 } | ||
).should.be.equal(1, "black x white"); | ||
expect( | ||
Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 255, g: 0, b: 0 }) | ||
).toEqual(0); | ||
|
||
expect( | ||
pct(Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 0, b: 0 })) | ||
).toEqual(33.3); | ||
|
||
expect( | ||
pct(Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 0 })) | ||
).toEqual(66.6); | ||
|
||
expect( | ||
Jimp.colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 255 }) | ||
).toEqual(1); | ||
|
||
expect( | ||
Jimp.colorDiff({ r: 0, g: 0, b: 0 }, { r: 255, g: 255, b: 255 }) | ||
).toEqual(1); | ||
}); | ||
|
||
it("totally transparent", () => { | ||
Jimp.colorDiff( | ||
{ r: 255, g: 0, b: 0, a: 0 }, | ||
{ r: 255, g: 0, b: 0, a: 0 } | ||
).should.be.equal(0, "both transparent red"); | ||
|
||
Jimp.colorDiff( | ||
{ r: 0, g: 0, b: 0, a: 0 }, | ||
{ r: 255, g: 255, b: 255, a: 0 } | ||
).should.be.equal(1, "transparent black x transparent white"); | ||
expect( | ||
Jimp.colorDiff({ r: 255, g: 0, b: 0, a: 0 }, { r: 255, g: 0, b: 0, a: 0 }) | ||
).toEqual(0); | ||
|
||
expect( | ||
Jimp.colorDiff( | ||
{ r: 0, g: 0, b: 0, a: 0 }, | ||
{ r: 255, g: 255, b: 255, a: 0 } | ||
) | ||
).toEqual(1); | ||
}); | ||
|
||
it("different alpha", () => { | ||
pct( | ||
Jimp.colorDiff( | ||
{ r: 255, g: 0, b: 0, a: 100 }, | ||
{ r: 255, g: 0, b: 0, a: 150 } | ||
expect( | ||
pct( | ||
Jimp.colorDiff( | ||
{ r: 255, g: 0, b: 0, a: 100 }, | ||
{ r: 255, g: 0, b: 0, a: 150 } | ||
) | ||
) | ||
).should.be.equal(3.8, "both red"); | ||
).toEqual(3.8); | ||
|
||
Jimp.colorDiff( | ||
{ r: 0, g: 0, b: 0, a: 0 }, | ||
{ r: 255, g: 255, b: 255, a: 255 } | ||
).should.be.equal(1, "transparent black x transparent white"); | ||
expect( | ||
Jimp.colorDiff( | ||
{ r: 0, g: 0, b: 0, a: 0 }, | ||
{ r: 255, g: 255, b: 255, a: 255 } | ||
) | ||
).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.