Skip to content

Commit 634110d

Browse files
author
Musa Kaçmaz
committed
Bitmap size error added and license updated
1 parent 6dce0c4 commit 634110d

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

__tests__/models/bitmap.test.ts renamed to __tests__/unit/models/bitmap.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Bitmap } from '../../src/models/bitmap';
2-
import { Helper } from '../helper';
1+
import { Bitmap } from '../../../src/models/bitmap';
2+
import { Helper } from '../../helper';
33

44
describe('Bitmap Class Tests', () => {
55
const bitmap: Bitmap = Helper.seedBitmapData();

__tests__/models/pixel.test.ts renamed to __tests__/unit/models/pixel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Pixel } from '../../src/models/pixel';
1+
import { Pixel } from '../../../src/models/pixel';
22

33
describe('Pixel Class Tests', () => {
44
const pixel: Pixel = new Pixel(0, 1, 0);

__tests__/utilities/distanceCalculator.test.ts renamed to __tests__/unit/utilities/distanceCalculator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { DistanceCalculator } from '../../src/utilities/distanceCalculator';
2-
import { Bitmap } from '../../src/models/bitmap';
3-
import { Pixel } from '../../src/models/pixel';
4-
import { Helper } from '../helper';
1+
import { DistanceCalculator } from '../../../src/utilities/distanceCalculator';
2+
import { Bitmap } from '../../../src/models/bitmap';
3+
import { Pixel } from '../../../src/models/pixel';
4+
import { Helper } from '../../helper';
55

66
describe('DistanceCalculator Class Tests', () => {
77
const bitmap: Bitmap = Helper.seedBitmapData();

__tests__/utilities/parser.test.ts renamed to __tests__/unit/utilities/parser.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Parser } from '../../src/utilities/parser';
2-
import { invalidNumberOfTestCasesError } from '../../src/errors';
3-
import { Bitmap } from '../../src/models/bitmap';
1+
import { Parser } from '../../../src/utilities/parser';
2+
import { invalidNumberOfTestCasesError, invalidValueOfBitmapSize } from '../../../src/errors';
3+
import { Bitmap } from '../../../src/models/bitmap';
44

55
describe('Parser Class Tests', () => {
66
describe('evaluateLine', () => {
@@ -26,6 +26,18 @@ describe('Parser Class Tests', () => {
2626
expect(error.reason).toBe(invalidNumberOfTestCasesError().reason);
2727
}
2828
});
29+
it('should throw err when an invalid value of bitmap size come from the input', () => {
30+
const parser = new Parser();
31+
parser.evaluateLine('1');
32+
parser.evaluateLine('');
33+
try {
34+
parser.evaluateLine('3 183');
35+
} catch (error) {
36+
console.log('ERR: ', error);
37+
expect(error.type).toEqual(invalidValueOfBitmapSize().type);
38+
expect(error.reason).toBe(invalidValueOfBitmapSize().reason);
39+
}
40+
});
2941
});
3042

3143
describe('createBitmaps', () => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"challenge"
2323
],
2424
"author": "musa kaçmaz",
25-
"license": "ISC",
25+
"license": "MIT",
2626
"bugs": {
2727
"url": "https://github.com/musakacmaz/dott-assignment/issues"
2828
},

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ export abstract class Constants {
33
static readonly NUMBER_OF_TEST_CASES_MAX_VALUE: number = 1000;
44
static readonly PIXEL_COLORS_BLACK: number = 0;
55
static readonly PIXEL_COLORS_WHITE: number = 1;
6+
static readonly BITMAP_SIZE_MIN_VALUE: number = 1;
7+
static readonly BITMAP_SIZE_MAX_VALUE: number = 182;
68
}

src/errors.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
enum ErrorCode {
2-
InvalidNumberOfTestCases
2+
InvalidNumberOfTestCases,
3+
InvalidValueOfBitmapSize
34
}
45

56
interface Failure<FailureType extends number> {
@@ -11,3 +12,8 @@ export const invalidNumberOfTestCasesError = (): Failure<ErrorCode.InvalidNumber
1112
type: ErrorCode.InvalidNumberOfTestCases,
1213
reason: 'Invalid number of test cases!'
1314
});
15+
16+
export const invalidValueOfBitmapSize = (): Failure<ErrorCode.InvalidValueOfBitmapSize> => ({
17+
type: ErrorCode.InvalidValueOfBitmapSize,
18+
reason: 'Invalid value of bitmap size!'
19+
});

src/utilities/parser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Constants } from '../constants';
22
import { Bitmap } from '../models/bitmap';
33
import { Pixel } from '../models/pixel';
4-
import { invalidNumberOfTestCasesError } from '../errors';
4+
import { invalidNumberOfTestCasesError, invalidValueOfBitmapSize } from '../errors';
55

66
/**
77
* Interface for classes that describe a bitmap.
@@ -49,6 +49,12 @@ export class Parser {
4949

5050
if (line.includes(' ')) {
5151
const [lineSize, columnSize] = line.split(' ');
52+
if (
53+
!(Number(lineSize) >= Constants.BITMAP_SIZE_MIN_VALUE && Number(lineSize) <= Constants.BITMAP_SIZE_MAX_VALUE) ||
54+
!(Number(columnSize) >= Constants.BITMAP_SIZE_MIN_VALUE && Number(columnSize) <= Constants.BITMAP_SIZE_MAX_VALUE)
55+
) {
56+
throw invalidValueOfBitmapSize();
57+
}
5258
const newBitmapDescription: BitmapDescription = {
5359
lineSize: Number(lineSize),
5460
columnSize: Number(columnSize),

0 commit comments

Comments
 (0)