-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_loader_dependency_test.go
More file actions
661 lines (599 loc) · 20 KB
/
dynamic_loader_dependency_test.go
File metadata and controls
661 lines (599 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
// dynamic_loader_dependency_test.go: Block 2 - Dependency Graph Operations Testing
//
// BLOCK 2 FOCUS: Test critici per le operazioni di dependency graph management
// - AddPlugin: Gestione dependency graph e relazioni
// - RemovePlugin: Cleanup e integrity check durante rimozione
// - CalculateLoadOrder: Kahn's algorithm per topological sorting
// - ValidateDependencies: Circular dependency detection e missing deps
//
// Copyright (c) 2025 AGILira - A. Giordano
// Series: an AGILira library
// SPDX-License-Identifier: MPL-2.0
package goplugins
import (
"fmt"
"math/rand"
"sort"
"sync"
"testing"
"time"
)
// TestDynamicLoader_DependencyGraph_CoreFunctionality tests basic dependency graph operations
func TestDynamicLoader_DependencyGraph_CoreFunctionality(t *testing.T) {
t.Run("BasicGraphOperations_AddRemove", func(t *testing.T) {
tests := []struct {
name string
scenario func(*testing.T, *DependencyGraph)
}{
{"EmptyGraph_Initial", func(t *testing.T, dg *DependencyGraph) {
loadOrder, err := dg.CalculateLoadOrder()
if err != nil {
t.Errorf("Empty graph should have valid load order: %v", err)
}
if len(loadOrder) != 0 {
t.Errorf("Empty graph load order should be empty, got: %v", loadOrder)
}
}},
{"SinglePlugin_NoDependencies", func(t *testing.T, dg *DependencyGraph) {
err := dg.AddPlugin("plugin-a", []string{})
if err != nil {
t.Errorf("Failed to add simple plugin: %v", err)
}
loadOrder, err := dg.CalculateLoadOrder()
if err != nil {
t.Errorf("Failed to calculate load order: %v", err)
}
if len(loadOrder) != 1 || loadOrder[0] != "plugin-a" {
t.Errorf("Expected [plugin-a], got: %v", loadOrder)
}
}},
{"LinearChain_Dependencies", func(t *testing.T, dg *DependencyGraph) {
// Create chain: A -> B -> C
err := dg.AddPlugin("plugin-c", []string{})
if err != nil {
t.Errorf("Failed to add plugin-c: %v", err)
}
err = dg.AddPlugin("plugin-b", []string{"plugin-c"})
if err != nil {
t.Errorf("Failed to add plugin-b: %v", err)
}
err = dg.AddPlugin("plugin-a", []string{"plugin-b"})
if err != nil {
t.Errorf("Failed to add plugin-a: %v", err)
}
loadOrder, err := dg.CalculateLoadOrder()
if err != nil {
t.Errorf("Failed to calculate load order: %v", err)
}
// Verify correct order: C, B, A
expected := []string{"plugin-c", "plugin-b", "plugin-a"}
if !equalStringSlices(loadOrder, expected) {
t.Errorf("Expected %v, got: %v", expected, loadOrder)
}
}},
{"MultipleRoots_ParallelPaths", func(t *testing.T, dg *DependencyGraph) {
// Create: A -> C, B -> C (two roots)
err := dg.AddPlugin("plugin-c", []string{})
if err != nil {
t.Errorf("Failed to add plugin-c: %v", err)
}
err = dg.AddPlugin("plugin-a", []string{"plugin-c"})
if err != nil {
t.Errorf("Failed to add plugin-a: %v", err)
}
err = dg.AddPlugin("plugin-b", []string{"plugin-c"})
if err != nil {
t.Errorf("Failed to add plugin-b: %v", err)
}
loadOrder, err := dg.CalculateLoadOrder()
if err != nil {
t.Errorf("Failed to calculate load order: %v", err)
}
// C must be first, A and B can be in any order after
if len(loadOrder) != 3 || loadOrder[0] != "plugin-c" {
t.Errorf("plugin-c should be first in load order, got: %v", loadOrder)
}
// Check A and B are present
found := make(map[string]bool)
for _, plugin := range loadOrder {
found[plugin] = true
}
if !found["plugin-a"] || !found["plugin-b"] {
t.Errorf("Missing plugin-a or plugin-b in load order: %v", loadOrder)
}
}},
{"RemovePlugin_IntegrityCheck", func(t *testing.T, dg *DependencyGraph) {
// Build graph: A -> B -> C
if err := dg.AddPlugin("plugin-c", []string{}); err != nil {
t.Fatalf("Failed to add plugin-c: %v", err)
}
if err := dg.AddPlugin("plugin-b", []string{"plugin-c"}); err != nil {
t.Fatalf("Failed to add plugin-b: %v", err)
}
if err := dg.AddPlugin("plugin-a", []string{"plugin-b"}); err != nil {
t.Fatalf("Failed to add plugin-a: %v", err)
}
// Remove middle plugin
dg.RemovePlugin("plugin-b")
// Verify B is removed and dependencies cleaned up
deps := dg.GetDependencies("plugin-a")
if len(deps) != 1 || deps[0] != "plugin-b" {
t.Errorf("plugin-a dependencies should still be [plugin-b] (dangling ref), got: %v", deps)
}
// Verify load order calculation handles missing dependency
_, err := dg.CalculateLoadOrder()
if err == nil {
t.Error("Expected error due to missing dependency after removal")
}
}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dg := NewDependencyGraph()
test.scenario(t, dg)
})
}
t.Logf("✅ Basic dependency graph operations working correctly - tested %d scenarios", len(tests))
})
t.Run("KahnsAlgorithm_TopologicalSorting", func(t *testing.T) {
tests := []struct {
name string
setupGraph func(*DependencyGraph)
expectOrder []string
expectError bool
}{
{
"DiamondDependency",
func(dg *DependencyGraph) {
// D -> B, D -> C, B -> A, C -> A (diamond shape)
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("plugin-a", []string{})
addPluginOrFail("plugin-b", []string{"plugin-a"})
addPluginOrFail("plugin-c", []string{"plugin-a"})
addPluginOrFail("plugin-d", []string{"plugin-b", "plugin-c"})
},
[]string{"plugin-a"}, // A must be first
false,
},
{
"ComplexDAG_MultiLevel",
func(dg *DependencyGraph) {
// Complex: F -> D,E; D -> B; E -> C; B,C -> A
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("plugin-a", []string{})
addPluginOrFail("plugin-b", []string{"plugin-a"})
addPluginOrFail("plugin-c", []string{"plugin-a"})
addPluginOrFail("plugin-d", []string{"plugin-b"})
addPluginOrFail("plugin-e", []string{"plugin-c"})
addPluginOrFail("plugin-f", []string{"plugin-d", "plugin-e"})
},
[]string{"plugin-a"}, // A must be first
false,
},
{
"LargeGraph_Performance",
func(dg *DependencyGraph) {
// Create large linear chain for performance testing
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
for i := 0; i < 100; i++ {
name := fmt.Sprintf("plugin-%03d", i)
if i == 0 {
addPluginOrFail(name, []string{})
} else {
prev := fmt.Sprintf("plugin-%03d", i-1)
addPluginOrFail(name, []string{prev})
}
}
},
[]string{"plugin-000"}, // First plugin must be first
false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dg := NewDependencyGraph()
test.setupGraph(dg)
start := time.Now()
loadOrder, err := dg.CalculateLoadOrder()
duration := time.Since(start)
if test.expectError && err == nil {
t.Error("Expected error but got none")
} else if !test.expectError && err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !test.expectError {
// Verify expected elements are first
for i, expected := range test.expectOrder {
if i >= len(loadOrder) || loadOrder[i] != expected {
t.Errorf("Position %d: expected %s, got %v", i, expected, loadOrder)
}
}
}
// Performance check for large graphs
if test.name == "LargeGraph_Performance" && duration > 10*time.Millisecond {
t.Logf("⚠️ Performance warning: large graph took %v", duration)
}
})
}
t.Logf("✅ Kahn's algorithm working correctly - tested %d complex scenarios", len(tests))
})
}
// TestDynamicLoader_DependencyGraph_EdgeCasesAndBugs tests edge cases and potential bugs
func TestDynamicLoader_DependencyGraph_EdgeCasesAndBugs(t *testing.T) {
t.Run("CircularDependencies_Detection", func(t *testing.T) {
circularTests := []struct {
name string
setupCycle func(*DependencyGraph)
description string
}{
{
"SimpleCircle_TwoNodes",
func(dg *DependencyGraph) {
_ = dg.AddPlugin("plugin-a", []string{"plugin-b"}) // Ignore error in circular test
_ = dg.AddPlugin("plugin-b", []string{"plugin-a"}) // Ignore error in circular test
},
"A -> B -> A",
},
{
"SelfLoop_SingleNode",
func(dg *DependencyGraph) {
_ = dg.AddPlugin("plugin-a", []string{"plugin-a"}) // Ignore error in self-loop test
},
"A -> A",
},
{
"ThreeNodeCycle",
func(dg *DependencyGraph) {
_ = dg.AddPlugin("plugin-a", []string{"plugin-b"}) // Ignore error in circular test
_ = dg.AddPlugin("plugin-b", []string{"plugin-c"}) // Ignore error in circular test
_ = dg.AddPlugin("plugin-c", []string{"plugin-a"}) // Ignore error in circular test
},
"A -> B -> C -> A",
},
{
"ComplexCycle_WithValidNodes",
func(dg *DependencyGraph) {
// Valid part
_ = dg.AddPlugin("valid-1", []string{}) // Ignore error in circular test
_ = dg.AddPlugin("valid-2", []string{"valid-1"}) // Ignore error in circular test
// Cycle part
_ = dg.AddPlugin("cycle-a", []string{"cycle-b", "valid-1"}) // Ignore error in circular test
_ = dg.AddPlugin("cycle-b", []string{"cycle-c"}) // Ignore error in circular test
_ = dg.AddPlugin("cycle-c", []string{"cycle-a"}) // Ignore error in circular test
},
"Mixed valid + A -> B -> C -> A",
},
{
"LongCycle_Performance",
func(dg *DependencyGraph) {
// Create long cycle for stress testing
const cycleLength = 50
for i := 0; i < cycleLength; i++ {
name := fmt.Sprintf("cycle-%d", i)
nextName := fmt.Sprintf("cycle-%d", (i+1)%cycleLength)
_ = dg.AddPlugin(name, []string{nextName}) // Ignore error in circular test
}
},
"50-node circular chain",
},
}
var detectedCycles int
for _, test := range circularTests {
t.Run(test.name, func(t *testing.T) {
dg := NewDependencyGraph()
test.setupCycle(dg)
// Test CalculateLoadOrder
_, err := dg.CalculateLoadOrder()
if err == nil {
t.Errorf("Expected circular dependency error for %s", test.description)
} else {
detectedCycles++
t.Logf("✅ Correctly detected circular dependency: %s", test.description)
}
// Test ValidateDependencies
err = dg.ValidateDependencies()
if err == nil {
t.Errorf("ValidateDependencies should detect circular dependency for %s", test.description)
}
})
}
if detectedCycles == len(circularTests) {
t.Logf("✅ All %d circular dependency scenarios correctly detected", detectedCycles)
} else {
t.Errorf("Only detected %d/%d circular dependencies", detectedCycles, len(circularTests))
}
})
t.Run("MissingDependencies_ErrorHandling", func(t *testing.T) {
missingDepTests := []struct {
name string
setupGraph func(*DependencyGraph)
description string
}{
{
"SingleMissing_AfterRemoval",
func(dg *DependencyGraph) {
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("dependency", []string{})
addPluginOrFail("plugin-a", []string{"dependency"})
dg.RemovePlugin("dependency") // Create dangling reference
},
"A depends on plugin that was removed",
},
{
"MultipleMissing_AfterRemoval",
func(dg *DependencyGraph) {
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("dep-1", []string{})
addPluginOrFail("dep-2", []string{})
addPluginOrFail("plugin-a", []string{"dep-1", "dep-2"})
dg.RemovePlugin("dep-1")
dg.RemovePlugin("dep-2") // Both dependencies removed
},
"A depends on multiple removed plugins",
},
{
"ChainWithMissing_MiddleNode",
func(dg *DependencyGraph) {
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("plugin-c", []string{})
addPluginOrFail("plugin-b", []string{"plugin-c"})
addPluginOrFail("plugin-a", []string{"plugin-b"})
dg.RemovePlugin("plugin-b") // Remove middle dependency
},
"Chain with removed middle node",
},
{
"ComplexMissing_PartialRemoval",
func(dg *DependencyGraph) {
// Create valid graph
addPluginOrFail := func(name string, deps []string) {
if err := dg.AddPlugin(name, deps); err != nil {
panic(fmt.Sprintf("Failed to add plugin %s: %v", name, err))
}
}
addPluginOrFail("base", []string{})
addPluginOrFail("middle", []string{"base"})
addPluginOrFail("top", []string{"middle", "base"})
// Remove middle dependency
dg.RemovePlugin("middle")
},
"Complex graph with partial dependency removal",
},
}
var detectedMissing int
for _, test := range missingDepTests {
t.Run(test.name, func(t *testing.T) {
dg := NewDependencyGraph()
test.setupGraph(dg)
// Test ValidateDependencies
err := dg.ValidateDependencies()
if err == nil {
t.Errorf("Expected missing dependency error for: %s", test.description)
} else {
detectedMissing++
t.Logf("✅ Correctly detected missing dependency: %s", test.description)
}
// Test CalculateLoadOrder (should also fail)
_, err = dg.CalculateLoadOrder()
if err == nil {
t.Errorf("CalculateLoadOrder should fail for missing dependency: %s", test.description)
}
})
}
t.Logf("✅ All %d missing dependency scenarios correctly detected", detectedMissing)
})
t.Run("GraphIntegrity_AfterModifications", func(t *testing.T) {
tests := []struct {
name string
operation func(*DependencyGraph) string
}{
{
"AddDuplicate_Plugin",
func(dg *DependencyGraph) string {
if err := dg.AddPlugin("plugin-a", []string{}); err != nil {
return fmt.Sprintf("Failed to add plugin-a initially: %v", err)
}
if err := dg.AddPlugin("plugin-a", []string{"plugin-b"}); err != nil {
return fmt.Sprintf("Failed to update plugin-a dependencies: %v", err)
}
deps := dg.GetDependencies("plugin-a")
if len(deps) != 1 || deps[0] != "plugin-b" {
return fmt.Sprintf("Expected [plugin-b], got %v", deps)
}
return ""
},
},
{
"RemoveNonExistent_Plugin",
func(dg *DependencyGraph) string {
dg.RemovePlugin("non-existent") // Should not panic
return ""
},
},
{
"ModifyDependencies_UpdateRelations",
func(dg *DependencyGraph) string {
if err := dg.AddPlugin("plugin-a", []string{"plugin-b"}); err != nil {
return fmt.Sprintf("Failed to add plugin-a: %v", err)
}
if err := dg.AddPlugin("plugin-b", []string{}); err != nil {
return fmt.Sprintf("Failed to add plugin-b: %v", err)
}
if err := dg.AddPlugin("plugin-a", []string{"plugin-c"}); err != nil {
return fmt.Sprintf("Failed to update plugin-a dependencies: %v", err)
}
// Verify old relationship cleaned up
dependents := dg.GetDependents("plugin-b")
for _, dep := range dependents {
if dep == "plugin-a" {
return "plugin-b should no longer have plugin-a as dependent"
}
}
return ""
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
dg := NewDependencyGraph()
if errMsg := test.operation(dg); errMsg != "" {
t.Error(errMsg)
}
})
}
t.Logf("✅ Graph integrity maintained through all modification scenarios")
})
}
// TestDynamicLoader_DependencyGraph_ConcurrencyAndPerformance tests thread safety and performance
func TestDynamicLoader_DependencyGraph_ConcurrencyAndPerformance(t *testing.T) {
t.Run("ConcurrentAccess_ThreadSafety", func(t *testing.T) {
dg := NewDependencyGraph()
const goroutines = 20
const operationsPerGoroutine = 100
var wg sync.WaitGroup
errors := make(chan string, goroutines*operationsPerGoroutine)
// Concurrent operations
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
// Use local random generator instead of deprecated global Seed
rng := rand.New(rand.NewSource(time.Now().UnixNano() + int64(id)))
for j := 0; j < operationsPerGoroutine; j++ {
pluginName := fmt.Sprintf("plugin-%d-%d", id, j)
switch rng.Intn(4) {
case 0: // AddPlugin
deps := []string{}
if j > 0 {
deps = []string{fmt.Sprintf("plugin-%d-%d", id, j-1)}
}
if err := dg.AddPlugin(pluginName, deps); err != nil {
errors <- fmt.Sprintf("AddPlugin error: %v", err)
}
case 1: // RemovePlugin
if j > 0 {
dg.RemovePlugin(fmt.Sprintf("plugin-%d-%d", id, j-1))
}
case 2: // GetDependencies
dg.GetDependencies(pluginName)
case 3: // CalculateLoadOrder
_, _ = dg.CalculateLoadOrder() // Ignore result in stress test
}
}
}(i)
}
wg.Wait()
close(errors)
// Check for errors
var errorCount int
for err := range errors {
t.Logf("Concurrent error: %s", err)
errorCount++
}
if errorCount > 0 {
t.Errorf("Encountered %d errors during concurrent operations", errorCount)
} else {
t.Logf("✅ Concurrency test passed - %d goroutines × %d operations completed safely",
goroutines, operationsPerGoroutine)
}
})
t.Run("Performance_LargeGraphOperations", func(t *testing.T) {
dg := NewDependencyGraph()
// Build large graph
const graphSize = 1000
start := time.Now()
// Create chain dependencies for predictable performance
for i := 0; i < graphSize; i++ {
pluginName := fmt.Sprintf("plugin-%04d", i)
var deps []string
if i > 0 {
deps = []string{fmt.Sprintf("plugin-%04d", i-1)}
}
if err := dg.AddPlugin(pluginName, deps); err != nil {
t.Fatalf("Failed to add plugin %s: %v", pluginName, err)
}
}
buildTime := time.Since(start)
// Calculate load order
start = time.Now()
loadOrder, err := dg.CalculateLoadOrder()
calcTime := time.Since(start)
if err != nil {
t.Fatalf("Failed to calculate load order: %v", err)
}
if len(loadOrder) != graphSize {
t.Errorf("Expected %d plugins in load order, got %d", graphSize, len(loadOrder))
}
// Performance assertions
if buildTime > 100*time.Millisecond {
t.Logf("⚠️ Performance warning: building %d-node graph took %v", graphSize, buildTime)
}
if calcTime > 50*time.Millisecond {
t.Logf("⚠️ Performance warning: calculating load order for %d nodes took %v", graphSize, calcTime)
}
t.Logf("✅ Performance test completed - %d nodes: build=%v, calc=%v",
graphSize, buildTime, calcTime)
})
t.Run("MemoryUsage_StressTest", func(t *testing.T) {
// Test for memory leaks during intensive operations
dg := NewDependencyGraph()
const iterations = 1000
for i := 0; i < iterations; i++ {
// Add plugins
for j := 0; j < 10; j++ {
name := fmt.Sprintf("temp-%d-%d", i, j)
deps := []string{}
if j > 0 {
deps = []string{fmt.Sprintf("temp-%d-%d", i, j-1)}
}
_ = dg.AddPlugin(name, deps) // Ignore error in stress test
}
// Calculate order
_, _ = dg.CalculateLoadOrder() // Ignore result in stress test
// Remove plugins (cleanup)
for j := 0; j < 10; j++ {
name := fmt.Sprintf("temp-%d-%d", i, j)
dg.RemovePlugin(name)
}
}
t.Logf("✅ Memory stress test completed - %d iterations of add/calc/remove cycles", iterations)
})
}
// Helper functions
func equalStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
}
sort.Strings(a)
sort.Strings(b)
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}