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 | package main | ||||||
| 
 | 
 | ||||||
| import ( |  | ||||||
| 	"fmt" |  | ||||||
| 	"gotest/unique" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| func main() { | 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 | 	output int | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var test = []testdata{ | var odd_test = []testdata{ | ||||||
| 	{[]int{9, 3, 9, 3, 9, 7, 9}, 7}, | 	{[]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}, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // сравниваем входные данные с выходными данными, и кидаем ошибки или пишем в терминал
 | ||||||
|  | func test(d *testdata, t *testing.T) { | ||||||
|  | 
 | ||||||
|  | 	result := unique.FindUnique(d.input) | ||||||
|  | 
 | ||||||
|  | 	if result != d.output { | ||||||
|  | 		t.Error( | ||||||
|  | 			"test failed", | ||||||
|  | 			"for: ", d.input, | ||||||
|  | 			"expected: ", d.output, | ||||||
|  | 			"got: ", result, | ||||||
|  | 		) | ||||||
|  | 	} else { | ||||||
|  | 		fmt.Println( | ||||||
|  | 			"test passed", | ||||||
|  | 			"for: ", d.input, | ||||||
|  | 			"got: ", result, | ||||||
|  | 		) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func TestUnique(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	t.Run( | 	t.Run( | ||||||
| 		"insert nums", func(t *testing.T) { | 		"inserting odd nums of elements", func(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 			for _, data := range test { | 			for _, data := range odd_test { | ||||||
| 
 | 
 | ||||||
| 				result := unique.FindUnique(data.input) | 				test(&data, &testing.T{}) | ||||||
|  | 
 | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
|  | 	) | ||||||
|  | 
 | ||||||
|  | 	t.Run( | ||||||
|  | 		"inserting even nums of elements", func(t *testing.T) { | ||||||
|  | 
 | ||||||
|  | 			for _, data := range even_test { | ||||||
|  | 
 | ||||||
|  | 				test(&data, &testing.T{}) | ||||||
| 
 | 
 | ||||||
| 				if result != data.output { |  | ||||||
| 					t.Error( |  | ||||||
| 						"For: ", data.input, |  | ||||||
| 						"Expected: ", data.output, |  | ||||||
| 						"Got: ", result, |  | ||||||
| 					) |  | ||||||
| 				} else { |  | ||||||
| 					fmt.Println( |  | ||||||
| 						"For: ", data.input, |  | ||||||
| 						"Got: ", result, |  | ||||||
| 					) |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue