File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -430,6 +430,27 @@ func TestReplaceRune(t *testing.T) {
430
430
}
431
431
}
432
432
433
+ func TestReplaceRuneConcurrent (t * testing.T ) {
434
+ sb := NewStringBuilderFromString ("Hello" )
435
+
436
+ var wg sync.WaitGroup
437
+ wg .Add (NumOfThreads )
438
+ for i := 0 ; i < NumOfThreads ; i ++ {
439
+ go func () {
440
+ defer wg .Done ()
441
+ for j := 0 ; j < NumOfIterations ; j ++ {
442
+ sb .ReplaceRune ('l' , 'm' )
443
+ }
444
+ }()
445
+ }
446
+
447
+ wg .Wait ()
448
+
449
+ if got := sb .ToString (); got != "Hemmo" {
450
+ t .Errorf ("StringBuilder.ReplaceRune() = %v, want %v" , got , "Hemmo" )
451
+ }
452
+ }
453
+
433
454
func TestReplace (t * testing.T ) {
434
455
tests := []struct {
435
456
name string
@@ -546,6 +567,28 @@ func TestReuseReversedStringBuilder(t *testing.T) {
546
567
}
547
568
}
548
569
570
+ func TestReverseStringBuilderConcurrent (t * testing.T ) {
571
+ sb := NewStringBuilderFromString ("ABC" )
572
+
573
+ var wg sync.WaitGroup
574
+ wg .Add (NumOfThreads )
575
+ for i := 0 ; i < NumOfThreads ; i ++ {
576
+ go func () {
577
+ defer wg .Done ()
578
+ for j := 0 ; j < NumOfIterations ; j ++ {
579
+ sb = sb .Reverse ()
580
+ }
581
+ }()
582
+ }
583
+
584
+ wg .Wait ()
585
+
586
+ expected := "ABC" // We expect the original string as we have reversed NumOfThreads * NumOfIterations times which is even
587
+ if got := sb .ToString (); got != expected {
588
+ t .Errorf ("StringBuilder.Reverse() = %v, want %v" , got , expected )
589
+ }
590
+ }
591
+
549
592
func TestStringBuilderSubstring (t * testing.T ) {
550
593
tests := []struct {
551
594
name string
You can’t perform that action at this time.
0 commit comments