let it go

Finished
1import { describe, it } from 'node:test';
2import { square, total } from './main.js';
3import { strict as assert } from 'node:assert';
4
5describe('Grains', () => {
6 describe('square', () => {
7 /**
8 * Test case: verify the function correctly calculates grains for square 1
9 * This tests the base case where the first square should have exactly 1 grain
10 */
11 it('should return 1 grain for square 1', () => {
12 assert.equal(square(1), BigInt(1));
13 });
14
15 /**
16 * Test case: verify the function correctly calculates grains for square 2
17 * This tests that the second square has 2 grains (2^1)
18 */
19 it('should return 2 grains for square 2', () => {
20 assert.equal(square(2), BigInt(2));
21 });
22
23 /**
24 * Test case: verify the function correctly calculates grains for square 3
25 * This tests that the third square has 4 grains (2^2)
26 */
27 it('should return 4 grains for square 3', () => {
28 assert.equal(square(3), BigInt(4));
29 });
30
31 /**
32 * Test case: verify the function correctly calculates grains for square 4
33 * This tests that the fourth square has 8 grains (2^3)
34 */
35 it('should return 8 grains for square 4', () => {
36 assert.equal(square(4), BigInt(8));
37 });
38
39 /**
40 * Test case: verify the function correctly calculates grains for square 16
41 * This tests a mid-range square to ensure the exponential growth is calculated correctly
42 */
43 it('should return 32768 grains for square 16', () => {
44 assert.equal(square(16), BigInt(32768));
45 });
46
47 /**
48 * Test case: verify the function correctly calculates grains for square 32
49 * This tests a higher square number to ensure the exponential growth is calculated correctly
50 */
51 it('should return 2147483648 grains for square 32', () => {
52 assert.equal(square(32), BigInt(2147483648));
53 });
54
55 /**
56 * Test case: verify the function correctly calculates grains for square 64
57 * This tests the maximum valid square to ensure the exponential growth is calculated correctly
58 * Edge case: tests the largest possible input value
59 */
60 it('should return 9223372036854775808 grains for square 64', () => {
61 assert.equal(square(64), BigInt('9223372036854775808'));
62 });
63
64 /**
65 * Test case: verify the function throws an error for square 0
66 * Edge case: tests that inputs below the valid range are rejected
67 */
68 it('should throw an error for square 0', () => {
69 assert.throws(() => square(0), new Error('square must be between 1 and 64'));
70 });
71
72 /**
73 * Test case: verify the function throws an error for negative square numbers
74 * Edge case: tests that negative inputs are rejected
75 */
76 it('should throw an error for negative square numbers', () => {
77 assert.throws(() => square(-1), new Error('square must be between 1 and 64'));
78 });
79
80 /**
81 * Test case: verify the function throws an error for square numbers greater than 64
82 * Edge case: tests that inputs above the valid range are rejected
83 */
84 it('should throw an error for square numbers greater than 64', () => {
85 assert.throws(() => square(65), new Error('square must be between 1 and 64'));
86 });
87 });
88
89 describe('total', () => {
90 /**
91 * Test case: verify the function correctly calculates the total grains on the chessboard
92 * This tests that the sum of all grains from squares 1 to 64 is calculated correctly
93 * The total should be 2^64 - 1, which is the sum of a geometric series
94 */
95 it('should return the total number of grains on the chessboard', () => {
96 assert.equal(total(), BigInt('18446744073709551615'));
97 });
98 });
99});
Test NameStatus
grains on square 1
Pass
grains on square 2
Pass
grains on square 3
Pass
grains on square 4
Pass
grains on square 16
Pass
grains on square 32
Pass
grains on square 64
Pass
square 0 raises an exception
Pass
negative square raises an exception
Pass
square greater than 64 raises an exception
Pass
returns the total number of grains on the board
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.