some changes in unique and unique test
This commit is contained in:
		
							parent
							
								
									9b85b8749f
								
							
						
					
					
						commit
						376ff4255a
					
				
							
								
								
									
										7
									
								
								main.go
								
								
								
								
							
							
						
						
									
										7
									
								
								main.go
								
								
								
								
							|  | @ -1,12 +1,5 @@ | |||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"gotest/unique" | ||||
| ) | ||||
| 
 | ||||
| func main() { | ||||
| 	var nums = []int{2, 2, 4, 5, 4, 6, 6} | ||||
| 
 | ||||
| 	fmt.Println(unique.FindUnique(nums)) | ||||
| } | ||||
|  |  | |||
|  | @ -14,32 +14,56 @@ type testdata struct { | |||
| 	output int | ||||
| } | ||||
| 
 | ||||
| var test = []testdata{ | ||||
| var odd_test = []testdata{ | ||||
| 	{[]int{9, 3, 9, 3, 9, 7, 9}, 7}, | ||||
| 	{[]int{9, 3, 9, 8, 9, 7, 9}, 3}, | ||||
| 	{[]int{9, 3, 9, 8, 9, 3, 9}, 8}, | ||||
| } | ||||
| 
 | ||||
| func TestRotation(t *testing.T) { | ||||
| var even_test = []testdata{ | ||||
| 	{[]int{9, 3, 9, 3, 9, 7}, 0}, | ||||
| } | ||||
| 
 | ||||
| 	t.Run( | ||||
| 		"insert nums", func(t *testing.T) { | ||||
| // сравниваем входные данные с выходными данными, и кидаем ошибки или пишем в терминал
 | ||||
| func test(d *testdata, t *testing.T) { | ||||
| 
 | ||||
| 			for _, data := range test { | ||||
| 	result := unique.FindUnique(d.input) | ||||
| 
 | ||||
| 				result := unique.FindUnique(data.input) | ||||
| 
 | ||||
| 				if result != data.output { | ||||
| 	if result != d.output { | ||||
| 		t.Error( | ||||
| 						"For: ", data.input, | ||||
| 						"Expected: ", data.output, | ||||
| 						"Got: ", result, | ||||
| 			"test failed", | ||||
| 			"for: ", d.input, | ||||
| 			"expected: ", d.output, | ||||
| 			"got: ", result, | ||||
| 		) | ||||
| 	} else { | ||||
| 		fmt.Println( | ||||
| 						"For: ", data.input, | ||||
| 						"Got: ", result, | ||||
| 			"test passed", | ||||
| 			"for: ", d.input, | ||||
| 			"got: ", result, | ||||
| 		) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestUnique(t *testing.T) { | ||||
| 
 | ||||
| 	t.Run( | ||||
| 		"inserting odd nums of elements", func(t *testing.T) { | ||||
| 
 | ||||
| 			for _, data := range odd_test { | ||||
| 
 | ||||
| 				test(&data, &testing.T{}) | ||||
| 
 | ||||
| 			} | ||||
| 		}, | ||||
| 	) | ||||
| 
 | ||||
| 	t.Run( | ||||
| 		"inserting even nums of elements", func(t *testing.T) { | ||||
| 
 | ||||
| 			for _, data := range even_test { | ||||
| 
 | ||||
| 				test(&data, &testing.T{}) | ||||
| 
 | ||||
| 			} | ||||
| 		}, | ||||
| 	) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue