Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Sep 2, 2024
2 parents e897c35 + 6c114a5 commit edd6751
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions compare/deep/deep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ namespace $ {

} ,

'same POJOs with cyclic reference with cache warmup'() {
const obj1 = { test: 1, obj3: null as unknown as Object }
const obj1_copy = { test: 1, obj3: null as unknown as Object }
const obj2 = { test: 2, obj1 }
const obj2_copy = { test: 2, obj1: obj1_copy }
const obj3 = { test: 3, obj2 }
const obj3_copy = { test: 3, obj2: obj2_copy }

obj1.obj3 = obj3
obj1_copy.obj3 = obj3_copy

// warmup cache
$mol_assert_not( $mol_compare_deep( obj1 , {} ) )
$mol_assert_not( $mol_compare_deep( obj2 , {} ) )
$mol_assert_not( $mol_compare_deep( obj3 , {} ) )

$mol_assert_ok( $mol_compare_deep( obj3 , obj3_copy ) )

} ,

'Date'() {
$mol_assert_ok( $mol_compare_deep( new Date( 12345 ) , new Date( 12345 ) ) )
$mol_assert_not( $mol_compare_deep( new Date( 12345 ) , new Date( 12346 ) ) )
Expand Down
4 changes: 3 additions & 1 deletion compare/deep/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ namespace $ {

} else {

left_cache = new WeakMap< any , boolean >([[ right, true ]])
left_cache = new WeakMap< any , boolean >()
$mol_compare_deep_cache.set( left , left_cache )

}

left_cache.set(right, true);

let result!: boolean

try {
Expand Down
2 changes: 1 addition & 1 deletion unit/money/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace $ {
}
}

export class $mol_unit_money_rur extends $mol_unit_money {
export class $mol_unit_money_rub extends $mol_unit_money {
postfix() {
return ' ₽'
}
Expand Down
2 changes: 1 addition & 1 deletion unit/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace $ {

var usd1 = new $mol_unit_money_usd( 2 )
var usd2 = new $mol_unit_money_usd( 3 )
var rur = new $mol_unit_money_rur( 2 )
var rur = new $mol_unit_money_rub( 2 )

$mol_assert_equal( $mol_unit.summ( usd1 , usd2 ).toString() , '$5' )
$mol_assert_equal( usd1.mult( 2 ).toString() , '$4' )
Expand Down

0 comments on commit edd6751

Please sign in to comment.