1+ import { describe , it , expect } from 'bun:test'
2+ import { canConstruct } from './ransom-note' ;
3+
4+ describe ( 'canConstruct' , ( ) => {
5+ it ( 'should return true when ransomNote can be constructed from magazine' , ( ) => {
6+ expect ( canConstruct ( 'a' , 'a' ) ) . toBe ( true ) ;
7+ expect ( canConstruct ( 'aa' , 'aab' ) ) . toBe ( true ) ;
8+ expect ( canConstruct ( 'abc' , 'cba' ) ) . toBe ( true ) ;
9+ } ) ;
10+
11+ it ( 'should return false when ransomNote cannot be constructed from magazine' , ( ) => {
12+ expect ( canConstruct ( 'aa' , 'ab' ) ) . toBe ( false ) ;
13+ expect ( canConstruct ( 'aaa' , 'aa' ) ) . toBe ( false ) ;
14+ expect ( canConstruct ( 'abcd' , 'abc' ) ) . toBe ( false ) ;
15+ } ) ;
16+
17+ it ( 'should return true for empty ransomNote' , ( ) => {
18+ expect ( canConstruct ( '' , 'anystring' ) ) . toBe ( true ) ;
19+ } ) ;
20+
21+ it ( 'should return false for empty magazine when ransomNote is not empty' , ( ) => {
22+ expect ( canConstruct ( 'a' , '' ) ) . toBe ( false ) ;
23+ } ) ;
24+
25+ it ( 'should return true when both ransomNote and magazine are empty' , ( ) => {
26+ expect ( canConstruct ( '' , '' ) ) . toBe ( true ) ;
27+ } ) ;
28+
29+ it ( 'should handle large inputs' , ( ) => {
30+ const ransomNote = 'a' . repeat ( 1000 ) ;
31+ const magazine = 'a' . repeat ( 1000 ) ;
32+ expect ( canConstruct ( ransomNote , magazine ) ) . toBe ( true ) ;
33+
34+ const magazineWithExtra = 'a' . repeat ( 1001 ) ;
35+ expect ( canConstruct ( ransomNote , magazineWithExtra ) ) . toBe ( true ) ;
36+
37+ const insufficientMagazine = 'a' . repeat ( 999 ) ;
38+ expect ( canConstruct ( ransomNote , insufficientMagazine ) ) . toBe ( false ) ;
39+ } ) ;
40+ } ) ;
0 commit comments