Integers and example tests
							parent
							
								
									ca7d449b44
								
							
						
					
					
						commit
						76f5fc442c
					
				@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					package integers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Add takes two integers and returns the sum of them.
 | 
				
			||||||
 | 
					func Add(x, y int) int {
 | 
				
			||||||
 | 
						return x + y
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package integers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAdder(t *testing.T) {
 | 
				
			||||||
 | 
						sum := Add(2, 2)
 | 
				
			||||||
 | 
						expected := 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if sum != expected {
 | 
				
			||||||
 | 
							t.Errorf("Expected '%d', but got '%d'", expected, sum)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// If your code changes so that the example is no longer valid, your build will fail.
 | 
				
			||||||
 | 
					func ExampleAdd() {
 | 
				
			||||||
 | 
						sum := Add(1, 5)
 | 
				
			||||||
 | 
						fmt.Println(sum)
 | 
				
			||||||
 | 
						// Output: 6
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					module integers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					go 1.21.0
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue