From 8066d3b4d01deece28b8ee47a31aa6d5326d3875 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 15 Dec 2023 16:11:00 -0600 Subject: [PATCH] chore(blp): add tests for BLP util functions (#25) --- src/spec/blp/util.spec.ts | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/spec/blp/util.spec.ts diff --git a/src/spec/blp/util.spec.ts b/src/spec/blp/util.spec.ts new file mode 100644 index 0000000..b816d6c --- /dev/null +++ b/src/spec/blp/util.spec.ts @@ -0,0 +1,40 @@ +import { calcLevelCount, getSizeAtMipLevel } from '../../lib/blp/util.js'; +import { describe, expect, test } from 'vitest'; + +describe('util', () => { + describe('calcLevelCount', () => { + test('should return expected level count for 512x512 dimensions', () => { + expect(calcLevelCount(512, 512)).toBe(10); + }); + + test('should return expected level count for 16x16 dimensions', () => { + expect(calcLevelCount(16, 16)).toBe(5); + }); + + test('should return expected level count for 1x1 dimensions', () => { + expect(calcLevelCount(1, 1)).toBe(1); + }); + + test('should return expected level count for 128x64 dimensions', () => { + expect(calcLevelCount(128, 64)).toBe(8); + }); + }); + + describe('getSizeAtMipLevel', () => { + test('should return expected size given initial size of 512 and mip level of 0', () => { + expect(getSizeAtMipLevel(512, 0)).toBe(512); + }); + + test('should return expected size given initial size of 512 and mip level of 1', () => { + expect(getSizeAtMipLevel(512, 1)).toBe(256); + }); + + test('should return expected size given initial size of 512 and mip level of 9', () => { + expect(getSizeAtMipLevel(512, 9)).toBe(1); + }); + + test('should return expected size given initial size of 2 and mip level of 1', () => { + expect(getSizeAtMipLevel(2, 1)).toBe(1); + }); + }); +});