1+ import { deepEquals } from "../src/utils" ;
2+
3+ describe ( 'deepEquals function tests' , ( ) => {
4+ describe ( 'primitive type comparison tests' , ( ) => {
5+ it ( 'should return true for equal numbers' , ( ) => {
6+ expect ( deepEquals ( 5 , 5 ) ) . toBe ( true ) ;
7+ } ) ;
8+
9+ it ( 'should return false for different numbers' , ( ) => {
10+ expect ( deepEquals ( 5 , 10 ) ) . toBe ( false ) ;
11+ } ) ;
12+
13+ it ( 'should return true for equal strings' , ( ) => {
14+ expect ( deepEquals ( 'hello' , 'hello' ) ) . toBe ( true ) ;
15+ } ) ;
16+
17+ it ( 'should return false for different strings' , ( ) => {
18+ expect ( deepEquals ( 'hello' , 'world' ) ) . toBe ( false ) ;
19+ } ) ;
20+
21+ it ( 'should return true for equal booleans' , ( ) => {
22+ expect ( deepEquals ( true , true ) ) . toBe ( true ) ;
23+ } ) ;
24+
25+ it ( 'should return false for different booleans' , ( ) => {
26+ expect ( deepEquals ( true , false ) ) . toBe ( false ) ;
27+ } ) ;
28+
29+ it ( 'should return false for number vs string' , ( ) => {
30+ expect ( deepEquals ( 5 , '5' ) ) . toBe ( false ) ;
31+ } ) ;
32+
33+ it ( 'should return false for null vs undefined' , ( ) => {
34+ expect ( deepEquals ( null , undefined ) ) . toBe ( false ) ;
35+ } ) ;
36+
37+ it ( 'should return true for null vs null' , ( ) => {
38+ expect ( deepEquals ( null , null ) ) . toBe ( true ) ;
39+ } ) ;
40+
41+ it ( 'should return true for undefined vs undefined' , ( ) => {
42+ expect ( deepEquals ( undefined , undefined ) ) . toBe ( true ) ;
43+ } ) ;
44+
45+ it ( 'should return false for NaN vs NaN since NaN is not supposed to equal itself' , ( ) => {
46+ expect ( deepEquals ( NaN , NaN ) ) . toBe ( false ) ;
47+ } ) ;
48+ } ) ;
49+
50+ describe ( 'object comparison tests' , ( ) => {
51+ it ( 'should return true for equal objects' , ( ) => {
52+ const obj1 = { a : 1 , b : { c : 2 } } ;
53+ const obj2 = { a : 1 , b : { c : 2 } } ;
54+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( true ) ;
55+ } ) ;
56+
57+ it ( 'should return false for objects with different properties' , ( ) => {
58+ const obj1 = { a : 1 , b : { c : 2 } } ;
59+ const obj2 = { a : 1 , b : { c : 3 } } ;
60+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( false ) ;
61+ } ) ;
62+
63+ it ( 'should return false for objects with different number of properties' , ( ) => {
64+ const obj1 = { a : 1 , b : { c : 2 } } ;
65+ const obj2 = { a : 1 } ;
66+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( false ) ;
67+ } ) ;
68+
69+ it ( 'should return false for objects with different nested structures' , ( ) => {
70+ const obj1 = { a : { b : { c : 2 } } } ;
71+ const obj2 = { a : { b : { d : 3 } } } ;
72+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( false ) ;
73+ } ) ;
74+
75+ // Arrays comparison
76+ it ( 'should return true for equal arrays' , ( ) => {
77+ const arr1 = [ 1 , 2 , 3 ] ;
78+ const arr2 = [ 1 , 2 , 3 ] ;
79+ expect ( deepEquals ( arr1 , arr2 ) ) . toBe ( true ) ;
80+ } ) ;
81+
82+ it ( 'should return false for arrays with different lengths' , ( ) => {
83+ const arr1 = [ 1 , 2 , 3 ] ;
84+ const arr2 = [ 1 , 2 ] ;
85+ expect ( deepEquals ( arr1 , arr2 ) ) . toBe ( false ) ;
86+ } ) ;
87+
88+ it ( 'should return false for arrays with different elements' , ( ) => {
89+ const arr1 = [ 1 , 2 , 3 ] ;
90+ const arr2 = [ 1 , 2 , 4 ] ;
91+ expect ( deepEquals ( arr1 , arr2 ) ) . toBe ( false ) ;
92+ } ) ;
93+
94+ it ( 'should return true for empty arrays' , ( ) => {
95+ const arr1 : unknown [ ] = [ ] ;
96+ const arr2 : unknown [ ] = [ ] ;
97+ expect ( deepEquals ( arr1 , arr2 ) ) . toBe ( true ) ;
98+ } ) ;
99+ } ) ;
100+
101+ describe ( 'mixed array and object comparison tests' , ( ) => {
102+ it ( 'should return false for object vs array' , ( ) => {
103+ const obj = { a : 1 } ;
104+ const arr = [ 1 ] ;
105+ expect ( deepEquals ( obj , arr ) ) . toBe ( false ) ;
106+ } ) ;
107+
108+ it ( 'should return false for array vs string' , ( ) => {
109+ const arr = [ 1 , 2 ] ;
110+ const str = '12' ;
111+ expect ( deepEquals ( arr , str ) ) . toBe ( false ) ;
112+ } ) ;
113+
114+ // Edge cases
115+ it ( 'should return true for empty objects' , ( ) => {
116+ expect ( deepEquals ( { } , { } ) ) . toBe ( true ) ;
117+ } ) ;
118+
119+ it ( 'should return true for empty arrays' , ( ) => {
120+ expect ( deepEquals ( [ ] , [ ] ) ) . toBe ( true ) ;
121+ } ) ;
122+
123+ it ( 'should return false for objects and null' , ( ) => {
124+ const obj = { a : 1 } ;
125+ expect ( deepEquals ( obj , null ) ) . toBe ( false ) ;
126+ } ) ;
127+
128+ it ( 'should return false for arrays and null' , ( ) => {
129+ const arr = [ 1 ] ;
130+ expect ( deepEquals ( arr , null ) ) . toBe ( false ) ;
131+ } ) ;
132+
133+ it ( 'should return false for functions' , ( ) => {
134+ const fn1 = ( ) => {
135+ } ;
136+ const fn2 = ( ) => {
137+ } ;
138+ expect ( deepEquals ( fn1 , fn2 ) ) . toBe ( false ) ;
139+ } ) ;
140+
141+ // Nested arrays and objects
142+ it ( 'should return true for deeply nested equal objects' , ( ) => {
143+ const obj1 = { a : { b : { c : 3 } } } ;
144+ const obj2 = { a : { b : { c : 3 } } } ;
145+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( true ) ;
146+ } ) ;
147+
148+ it ( 'should return false for deeply nested different objects' , ( ) => {
149+ const obj1 = { a : { b : { c : 3 } } } ;
150+ const obj2 = { a : { b : { c : 4 } } } ;
151+ expect ( deepEquals ( obj1 , obj2 ) ) . toBe ( false ) ;
152+ } ) ;
153+ } ) ;
154+ } ) ;
0 commit comments