@@ -423,6 +423,67 @@ func TestModifyNumericTypeMismatch(t *testing.T) {
423423 t .Log ("Skipping direct type mismatch test for ModifyNumeric on NumericCache[N] as it implies cache stores N." )
424424}
425425
426+ func TestIncrDecr (t * testing.T ) {
427+ nc := newNumericTestCache [int ](t , DefaultExpiration , 0 )
428+ nc .Set ("val" , 10 , DefaultExpiration )
429+
430+ // Test Incr
431+ newVal , err := nc .Incr ("val" , 5 )
432+ if err != nil {
433+ t .Fatalf ("Incr failed: %v" , err )
434+ }
435+ if newVal != 15 {
436+ t .Errorf ("Expected 15 after Incr, got %d" , newVal )
437+ }
438+
439+ // Test Decr
440+ newVal , err = nc .Decr ("val" , 3 )
441+ if err != nil {
442+ t .Fatalf ("Decr failed: %v" , err )
443+ }
444+ if newVal != 12 {
445+ t .Errorf ("Expected 12 after Decr, got %d" , newVal )
446+ }
447+ }
448+
449+ func TestIncrOverflow (t * testing.T ) {
450+ nc := newNumericTestCache [int8 ](t , DefaultExpiration , 0 )
451+ nc .Set ("int8" , int8 (127 ), DefaultExpiration )
452+
453+ newVal , err := nc .Incr ("int8" , 1 )
454+ if err != nil {
455+ t .Fatalf ("Incr failed: %v" , err )
456+ }
457+ if newVal != - 128 {
458+ t .Errorf ("Expected -128 after overflow, got %d" , newVal )
459+ }
460+ }
461+
462+ func TestDecrUnderflow (t * testing.T ) {
463+ nc := newNumericTestCache [uint8 ](t , DefaultExpiration , 0 )
464+ nc .Set ("uint8" , uint8 (0 ), DefaultExpiration )
465+
466+ newVal , err := nc .Decr ("uint8" , 1 )
467+ if err != nil {
468+ t .Fatalf ("Decr failed: %v" , err )
469+ }
470+ if newVal != 255 {
471+ t .Errorf ("Expected 255 after underflow, got %d" , newVal )
472+ }
473+ }
474+
475+ func TestIncrWithoutSet (t * testing.T ) {
476+ nc := newNumericTestCache [int ](t , DefaultExpiration , 0 )
477+
478+ newVal , err := nc .Incr ("newval" , 5 )
479+ if err != nil {
480+ t .Fatalf ("Incr failed: %v" , err )
481+ }
482+ if newVal != 5 {
483+ t .Errorf ("Expected 5 after Incr on empty key, got %d" , newVal )
484+ }
485+ }
486+
426487// --- End of ModifyNumeric Tests ---
427488
428489func TestAdd (t * testing.T ) {
0 commit comments