-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add unit-tests for colorspace.js #8611
Conversation
test/unit/colorspace_spec.js
Outdated
it('should be true if decode is not an array', function() { | ||
let test1 = new Test('I am a string', 0); | ||
let result1 = true; | ||
let returnValue1 = ColorSpace.isDefaultDecode(test1.decode, test1.n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the tests that you've currently added in the patch, I'm not sure why the code needs to be so verbose in these test-cases!?
Something along these lines ought to be perfectly sufficient:
expect(ColorSpace.isDefaultDecode('string', 0)).toBeTruthy(); // or .toBeFalsy() where applicable
or, if that doesn't fit on one line (e.g. below when you're passing arrays as arguments):
let someVariableName = [...];
expect(ColorSpace.isDefaultDecode(someVariableName, 0)).toBeTruthy();
test/unit/colorspace_spec.js
Outdated
import { ColorSpace } from '../../src/core/colorspace'; | ||
|
||
describe('colorspace', function () { | ||
class Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is necessary; see the suggestion in https://github.com/mozilla/pdf.js/pull/8611/files#r125623641.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait!, don't you need to import ColorSpace?
test/unit/colorspace_spec.js
Outdated
let result5 = false; | ||
let returnValue5 = ColorSpace.isDefaultDecode(test5.decode, test5.n); | ||
|
||
let test6 = new Test([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1], 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, I don't think the number of components will usually go beyond 4
, so you can probably use slightly shorter arrays here (and below too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Hi @Snuffleupagus , I made the appropriate changes. Please have a look and let me know. |
test/unit/colorspace_spec.js
Outdated
|
||
describe('colorspace', function () { | ||
it('should be true if decode is not an array', function() { | ||
expect(ColorSpace.isDefaultDecode('I am a string', 0)).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As indicated in #8611 (comment), please use toBeTruthy()
/toBeFalsy()
instead.
Also, please don't forget to squash the commits, see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
test/unit/colorspace_spec.js
Outdated
expect(ColorSpace.isDefaultDecode([0, 1], 1)).toBe(true); | ||
expect(ColorSpace.isDefaultDecode([1, 0], 1)).toBe(false); | ||
expect(ColorSpace.isDefaultDecode([1, 1], 1)).toBe(false); | ||
expect(ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 1, 1], 4)).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean for one of the last three cases to be truthy instead, since otherwise I'm not sure why you need so many (almost) identical test-cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they are meant to be falsy. I would change them, they look too verbose.
72dfc28
to
79fa82f
Compare
@Snuffleupagus , I made the changes and squashed the commits. Please have a look and let me know. |
Hi @Snuffleupagus , let me know if the changes look fine so that I may proceed further with this work and add tests for other functions too. Thanks. |
Since it's your first patch, and you explicitly asked for initial feedback, I provided some basic comments. However, I'm not sure if it's really necessary to review every small part piecewise at this point, so I'd suggest that we'll simply review it once you feel that the patch is complete :-) As for what additional tests you need to add, I think that it would be nice to at least have a few simple unit-tests for e.g. the following methods: |
60b2d52
to
016add5
Compare
016add5
to
d6d9b99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far! It's really good to have unit tests for this. I have added some comments about stylistic issues, so please resolve those to be consistent with the other parts of the codebase.
test/unit/colorspace_spec.js
Outdated
* limitations under the License. | ||
*/ | ||
|
||
import { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put these on one line since they fit within the 80 character limit.
test/unit/colorspace_spec.js
Outdated
Ref | ||
} from '../../src/core/primitives'; | ||
import { Stream, StringStream } from '../../src/core/stream'; | ||
import { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this on one line since they fit within the 80 character limit.
test/unit/colorspace_spec.js
Outdated
for (let elem in array) { | ||
let obj = array[elem]; | ||
let ref = obj.ref, | ||
data = obj.data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single lines should only contain one statement, so if you put this on a new line, make it let data = obj.data;
.
test/unit/colorspace_spec.js
Outdated
expect(ColorSpace.isDefaultDecode('string', 0)).toBeTruthy(); | ||
}); | ||
it('should be true if length of decode array is not correct', | ||
function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places in the patch as well.
In the other parts of the codebase, we format this as follows, so please do that here as well:
it('should be true if length of decode array is not correct',
function () {
expect(ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();
expect(ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();
});
In other words, the function
is intented with four spaces instead of two, while the body of the function is still indented with two spaces.
test/unit/colorspace_spec.js
Outdated
|
||
let testSrc = new Uint8Array([27, 125, 250, 131]); | ||
let testDest = new Uint8Array(4 * 4 * 3); | ||
let expectedDest = new Uint8Array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places in the patch as well.
Format this as follows:
let expectedDest = new Uint8Array([
27, 27, 27,
...,
131, 131, 131,
]);
test/unit/colorspace_spec.js
Outdated
|
||
expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual( | ||
new Uint8Array( | ||
[51, 51, 51])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places in the patch as well.
Move this back to the previous line.
test/unit/colorspace_spec.js
Outdated
|
||
let colorSpace = ColorSpace.parse(cs, xref, res); | ||
|
||
let testSrc = new Uint8Array([27, 125, 250, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places in the patch as well.
Put the part from the [
onward on the next line.
test/unit/colorspace_spec.js
Outdated
expect(testDest).toEqual(expectedDest); | ||
}); | ||
}); | ||
describe('CalRGBCS', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This applies to other places in the patch as well.
Please make sure that there is a newline before each describe
block for readability.
/botio unittest |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/0468a8a39ec70a2/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/7d9ef8d6b32836a/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/7d9ef8d6b32836a/output.txt Total script time: 2.55 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/0468a8a39ec70a2/output.txt Total script time: 12.10 mins
|
d6d9b99
to
86dedc1
Compare
Hi @timvandermeij , I resolved the stylistic issues as mentioned. Please have a look. |
86dedc1
to
df0f0f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides a couple of quick inline comments, is there any reason why these tests wouldn't work if run on Node.js?
If not, please add colorspace_spec.js
to the https://github.com/mozilla/pdf.js/blob/master/test/unit/clitests.json file.
test/unit/colorspace_spec.js
Outdated
|
||
describe('DeviceGrayCS', function () { | ||
it('should handle the case when cs is a Name object', function () { | ||
let cs = new Name('DeviceGray'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to comment on this once here, but it also applies in a number of places below:
Please use Name.get('DeviceGray')
instead, since that only creates one instance of the Name
object regardless of how many times it's called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/unit/colorspace_spec.js
Outdated
params.set('BlackPoint', [0, 0, 0]); | ||
params.set('Gamma', 2.0); | ||
|
||
let cs = new Array(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, and elsewhere too, using new Array
isn't necessary. Please just do:
let cs = [
Name.get('CalGray'),
params,
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK Added unit-tests for CalGray Added unit-tests for CalRGB Removed redundant code Added unit-tests for LabCS Added unit-tests for IndexedCS Update comment Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged). Added unit-tests for AlternateCS Resolved code-style issues Fixed code-style issues Addressed issues pointed out in mozilla#8611 (review)
df0f0f5
to
a129de7
Compare
/botio unittest |
From: Bot.io (Linux m4)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/17bb92ab174b2f8/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/a033a228a610cd9/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/17bb92ab174b2f8/output.txt Total script time: 2.55 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/a033a228a610cd9/output.txt Total script time: 12.36 mins
|
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/2c946f5b8ea04cb/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/66646a9eb6886a1/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/2c946f5b8ea04cb/output.txt Total script time: 16.54 mins
|
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/66646a9eb6886a1/output.txt Total script time: 29.02 mins
|
Thank you for providing the smoke tests! (The one unit tests failure is unrelated to this patch and passed before.) |
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK Added unit-tests for CalGray Added unit-tests for CalRGB Removed redundant code Added unit-tests for LabCS Added unit-tests for IndexedCS Update comment Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged). Added unit-tests for AlternateCS Resolved code-style issues Fixed code-style issues Addressed issues pointed out in mozilla#8611 (review)
Add unit-tests for colorspace.js
Hi, I have added some tests to check the
isDefaultDecode(...)
function in colorspace.js. I'll be adding the tests for other functions too. Please review and let me know the necessary changes to be made.Thanks.
Fixes #7261.