### Basic Git Workflow Example Source: https://github.com/veilair/test-driven-development/blob/main/contributing.md This snippet demonstrates the fundamental steps for starting a new feature branch, making commits, and pushing to a remote repository. ```shell git remote add upstream https://github.com/veilair/ git checkout -b my-new-feature master git commit -a git push origin my-new-feature ``` -------------------------------- ### Install Go Project Source: https://github.com/veilair/test-driven-development/blob/main/TDD-Goland_Example_2/README.md This command installs the Go project, compiling the package and generating an executable in the $GOPATH/bin directory. It assumes the repository is organized according to Go's standard directory structure. ```bash go install github.com/golang4dummies/golang-tdd ``` ```bash cd $GOPATH/golang4dummies/golang-tdd go install ``` -------------------------------- ### Dependency Injection for HTTP Handler in Go Source: https://context7.com/veilair/test-driven-development/llms.txt Demonstrates dependency injection using Go's io.Writer interface in a 'Greet' function. This allows the function to write to any output, including HTTP responses, making it easily testable with a bytes.Buffer. The example includes an HTTP server setup and a test function. ```go package main import ( "bytes" "fmt" "io" "net/http" ) // Greet writes a greeting to the provided writer func Greet(writer io.Writer, name string) { fmt.Fprintf(writer, "Hello, %s", name) } // MyGreetingsHandler HTTP handler using Greet func MyGreetingsHandler(w http.ResponseWriter, req *http.Request) { Greet(w, "world") } func main() { http.ListenAndServe(":5000", http.HandlerFunc(MyGreetingsHandler)) } // Test using buffer as io.Writer func TestGreet(t *testing.T) { buffer := bytes.Buffer{} Greet(&buffer, "Chris") got := buffer.String() want := "Hello, Chris" if got != want { t.Errorf("Got: '%s', Want: '%s' ", got, want) } } // Run server: go run greet.go // Test: curl http://localhost:5000 // Output: Hello, world // Run tests: go test -v ``` -------------------------------- ### Run Installed Go Program Source: https://github.com/veilair/test-driven-development/blob/main/TDD-Goland_Example_2/README.md After installing the Go package, this command executes the program. The executable is located in the $GOPATH/bin directory. If $GOPATH/bin is in your system's PATH, you can run it directly by its executable name. ```bash $GOPATH/bin/golang-tdd ``` ```bash golang-tdd ``` -------------------------------- ### Run Go Program Without Installation Source: https://github.com/veilair/test-driven-development/blob/main/TDD-Goland_Example_2/README.md This command allows you to compile and execute a Go program directly from its source file without needing to install it first. It's useful for quick testing or running single-file applications. ```bash go run qrcoded.go ``` -------------------------------- ### Go: Implement Money Value Object with TDD (Dollar) Source: https://context7.com/veilair/test-driven-development/llms.txt Demonstrates the Dollar type for USD currency, implementing multiplication and equality operations using TDD. This example is adapted from Kent Beck's 'Test-Driven Development by Example'. It includes tests for multiplication and equality checks. ```go package money import "testing" // Dollar holds money in the USD currency type Dollar struct { amount int } // Times multiply the value of Dollar by a given number and returns a new Dollar func (d *Dollar) Times(multiplier int) *Dollar { return &Dollar{d.amount * multiplier} } // Equals compare Dollar with everything else func (d *Dollar) Equals(i interface{}) bool { dollar, ok := i.(Dollar) return ok && d.amount == dollar.amount } // Example test demonstrating TDD approach func TestMultiplication(t *testing.T) { five := Dollar{5} if !five.Times(2).Equals(Dollar{10}) { t.Errorf("Expected to be 10!") } if !five.Times(3).Equals(Dollar{15}) { t.Errorf("Expected to be 15!") } } func TestEquality(t *testing.T) { five := Dollar{5} if !five.Equals(Dollar{5}) { t.Error("Expected to be equal!") } if five.Equals(Dollar{6}) { t.Error("Expected to be different!") } } // Run tests: go test -v -cover ``` -------------------------------- ### Sum and SumAll Functions for Slices (Go) Source: https://context7.com/veilair/test-driven-development/llms.txt Implements functions to sum elements in integer slices and handle variadic slices. Includes Sum, SumAllV2 (using variadic parameters), and SumAllTails (summing elements excluding the first). Demonstrates TDD with examples and tests. ```go package slices import ( "fmt" "reflect" ) func Sum(nums []int) int { var total int for _, v := range nums { total += v } return total } // SumAllV2 - Improved version using variadic parameters func SumAllV2(numbersToSum ...[]int) []int { var sums []int for _, nums := range numbersToSum { sums = append(sums, Sum(nums)) } return sums } // SumAllTails sums all elements except the first one from each slice func SumAllTails(numsToSum ...[]int) []int { var total []int for _, nums := range numsToSum { if len(nums) == 0 { total = append(total, 0) } else { tail := nums[1:] total = append(total, Sum(tail)) } } return total } var numbers = []int{2, 3, 4, 6, 9, 11} func ExampleSum() { result := Sum(numbers) fmt.Println(result) // Output: 35 } // Test with benchmarking func TestSum(t *testing.T) { t.Run("a collection of 5 numbers", func(t *testing.T) { got := Sum(numbers) expected := 35 if got != expected { t.Errorf("Expected: '%d', Got: '%d'", expected, got) } }) } func TestSumAllV2(t *testing.T) { got := SumAllV2([]int{1, 2}, []int{0, 9}) want := []int{3, 9} if !reflect.DeepEqual(got, want) { t.Errorf("Want: '%v', Got: '%v'", want, got) } } func TestSumAllTails(t *testing.T) { checkSums := func(t *testing.T, got, want []int) { t.Helper() if !reflect.DeepEqual(got, want) { t.Errorf("got %v want %v", got, want) } } t.Run("make the sums of tails of", func(t *testing.T) { got := SumAllTails([]int{1, 2}, []int{0, 9}) want := []int{2, 9} checkSums(t, got, want) }) t.Run("safely sum empty slices", func(t *testing.T) { got := SumAllTails([]int{}, []int{3, 4, 5}) want := []int{0, 9} checkSums(t, got, want) }) } func BenchmarkSum(b *testing.B) { for i := 0; i < b.N; i++ { Sum(numbers) } } // Run: go test -v // Benchmark: go test -bench=. ``` -------------------------------- ### Go: TDD for QR Code Generation Source: https://context7.com/veilair/test-driven-development/llms.txt Demonstrates TDD for image generation, specifically creating PNG-encoded QR code images. This example tests functions that produce binary output and handle I/O operations using Go's io.Writer interface, including error handling. ```go package main import ( "bytes" "errors" "image" "image/png" "io" "log" "os" "testing" ) func GenerateQRCode(w io.Writer, code string) error { img := image.NewNRGBA(image.Rect(0, 0, 21, 21)) return png.Encode(w, img) } func main() { file, err := os.Create("qrcode.png") if err != nil { log.Fatal(err) } defer file.Close() err = GenerateQRCode(file, "555-2368") if err != nil { log.Fatal(err) } } // ErrorWriter for testing error propagation type ErrorWriter struct{} func (e *ErrorWriter) Write(b []byte) (int, error) { return 0, errors.New("Expected error") } // Test that verifies PNG generation func TestGenerateQRCodeGeneratesPNG(t *testing.T) { buffer := new(bytes.Buffer) GenerateQRCode(buffer, "555-2368") if buffer.Len() == 0 { t.Errorf("Generated QR code length is zero") } _, err := png.Decode(buffer) if err != nil { t.Errorf("Generated QR Code is not a PNG: %s", err) } } // Test error handling func TestGenerateQRCodePropagatesErrors(t *testing.T) { w := new(ErrorWriter) err := GenerateQRCode(w, "555-2368") if err == nil { t.Errorf("Error not propagated correctly, got %v", err) } } // Run: go run qrcoded.go // Test: go test -v ``` -------------------------------- ### Squashing Changes into an Earlier Commit Source: https://github.com/veilair/test-driven-development/blob/main/contributing.md This example demonstrates using 'git commit --fixup' and 'git rebase -i --autosquash' to integrate changes into a specific earlier commit, useful for organizing commit history. ```shell git add . git commit --fixup git rebase -i --autosquash master git push --force-with-lease origin my-new-feature ``` -------------------------------- ### Syncing Local Branch with Upstream Master Source: https://github.com/veilair/test-driven-development/blob/main/contributing.md This example shows how to update a local feature branch with the latest changes from the upstream 'master' branch using fetch and rebase. ```shell git checkout my-new-feature git fetch -a git pull --rebase upstream master git push --force-with-lease origin my-new-feature ``` -------------------------------- ### Go Integer Arithmetic Functions with TDD Source: https://context7.com/veilair/test-driven-development/llms.txt Provides basic integer arithmetic functions in Go: Sum, Subtraction, Multipliation, and Division. Each function is accompanied by a corresponding test function to verify its correctness using TDD principles. An example of how to use the Sum function is also included. ```go package integers func Sum(x, y int) int { return x + y } func ExampleAdd() int { sum := Sum(1, 2) return sum // output 3 } func Subtraction(x, y int) int { return x - y } func Multipliation(x, y int) int { return x * y } func Division(x, y int) int { return x / y } // Test examples func TestAdder(t *testing.T) { sum := Sum(2, 2) expected := 4 if sum != expected { t.Errorf("expected '%d', got '%d'", expected, sum) } } func TestSubtration(t *testing.T) { difference := Subtraction(10, 5) expected := 5 if difference != expected { t.Errorf("expected '%d', got '%d'", expected, difference) } } func TestMultiplication(t *testing.T) { prod := Multipliation(2, 2) expected := 4 if prod != expected { t.Errorf("expected '%d', got '%d'", expected, prod) } } func TestDivision(t *testing.T) { div := Division(10, 5) expected := 2 if div != expected { t.Errorf("expected '%d', got '%d'", expected, div) } } // Run: go test -v ``` -------------------------------- ### Uninstall Go Project Source: https://github.com/veilair/test-driven-development/blob/main/TDD-Goland_Example_2/README.md This command cleans and uninstalls the Go project. It removes compiled files and any installed artifacts associated with the package. ```bash go clean -i ``` -------------------------------- ### Iteration Functions: Repeat and List Manipulation (Go) Source: https://context7.com/veilair/test-driven-development/llms.txt Provides functions for string repetition and list manipulation, including incrementing slice elements and converting strings to lowercase. Demonstrates TDD with examples and tests. ```go package iterations import ( "fmt" "reflect" "strings" ) func Repeat(val string, count int) string { var character string for i := 0; i <= count-1; i++ { character += val } return character } var list = []int{1, 3, 3, 4, 5, 6, 7} // PrintList increments each element by 1 func PrintList(val []int) []int { var manipulatedList []int for _, v := range val { manipulatedList = append(manipulatedList, v+1) } return manipulatedList } var fruits = []string{"Apple", "Orange", "Banana", "Grape"} // LowerCaseList converts all strings to lowercase func LowerCaseList(val []string) []string { var modifiedList []string for i := range val { s := strings.ToLower(val[i]) modifiedList = append(modifiedList, s) } return modifiedList } func ExampleRepeat() { result := Repeat("a", 6) fmt.Println(result) // Output: aaaaaa } func ExampleLowerCaseList() { result := LowerCaseList(fruits) fmt.Println(result) // Output: [apple orange banana grape] } func TestRepeat(t *testing.T) { t.Run("Testing the repeat function with 'a'", func(t *testing.T) { repeated := Repeat("a", 6) expected := "aaaaaa" if repeated != expected { t.Errorf("expected: '%s', got: '%s'", expected, repeated) } }) } func TestPrintList(t *testing.T) { t.Run("Testing with a list of integers", func(t *testing.T) { got := PrintList(list) expected := []int{2, 4, 4, 5, 6, 7, 8} if !reflect.DeepEqual(got, expected) { t.Errorf("expected: '%d', got: '%d'", expected, got) } }) } func TestLowerCaseList(t *testing.T) { t.Run("testing with a list of string", func(t *testing.T) { got := LowerCaseList(fruits) expected := []string{"apple", "orange", "banana", "grape"} if !reflect.DeepEqual(got, expected) { t.Errorf("expected: '%s', got: '%s'", expected, got) } }) } func BenchmarkRepeat(b *testing.B) { for i := 0; i < b.N; i++ { Repeat("a", 6) } } // Run: go test -v // Benchmark: go test -bench=. ``` -------------------------------- ### Go: Implement Money Value Object with TDD (Franc) Source: https://context7.com/veilair/test-driven-development/llms.txt Mirrors the Dollar implementation for CHF (Swiss Franc) currency, showcasing TDD for similar but distinct types. This example includes tests for Franc multiplication, ensuring correct behavior for the Swiss Franc currency. ```go package money import "testing" // Franc holds money in the CHF currency type Franc struct { amount int } // Times multiply the value of Franc by a given number and returns a new Franc func (f *Franc) Times(multiplier int) *Franc { return &Franc{f.amount * multiplier} } // Equals compare Franc with everything else func (f *Franc) Equals(i interface{}) bool { franc, ok := i.(Franc) return ok && f.amount == franc.amount } // Example test for Franc multiplication func TestFrancMultiplication(t *testing.T) { five := Franc{5} if !five.Times(2).Equals(Franc{10}) { t.Errorf("Expected to be 10!") } if !five.Times(3).Equals(Franc{15}) { t.Errorf("Expected to be 15!") } } // Run tests: go test -v -cover ``` -------------------------------- ### Mocking with Interfaces for Countdown in Go Source: https://context7.com/veilair/test-driven-development/llms.txt Illustrates mocking in TDD using an interface for time.Sleep. The 'Countdown' function accepts a 'Sleeper' interface, allowing a test double ('SpySleeper') to replace the real implementation during testing. This ensures fast and deterministic tests. The example includes the main function, the Countdown logic, a default sleeper, a spy sleeper, and a test function. ```go package main import ( "fmt" "io" "os" "time" ) const ( finalWord = "Go!" countdownStart = 3 ) // Sleeper interface for dependency injection type Sleeper interface { Sleep() } func main() { sleeper := &DefaultSleeper{} Countdown(os.Stdout, sleeper) } // Countdown prints a countdown then "Go!" func Countdown(out io.Writer, sleeper Sleeper) { for i := countdownStart; i > 0; i-- { sleeper.Sleep() } for i := countdownStart; i > 0; i-- { fmt.Fprintln(out, i) } sleeper.Sleep() fmt.Fprint(out, finalWord) } // DefaultSleeper real implementation type DefaultSleeper struct{} func (d *DefaultSleeper) Sleep() { time.Sleep(1 * time.Second) } // SpySleeper test double for counting Sleep calls type SpySleeper struct { Calls int } func (s *SpySleeper) Sleep() { s.Calls++ } // Example test with spy func TestCountdown(t *testing.T) { buffer := &bytes.Buffer{} spySleeper := &SpySleeper{} Countdown(buffer, spySleeper) got := buffer.String() want := `3 2 1 Go!` if got != want { t.Errorf("got '%s' want '%s'", got, want) } if spySleeper.Calls != 4 { t.Errorf("not enough calls to sleeper, want 4 got %d", spySleeper.Calls) } } // Run: go run countdown.go // Test: go test -v ``` -------------------------------- ### Go Hello Function with Multi-Language Support and TDD Source: https://context7.com/veilair/test-driven-development/llms.txt Implements a 'Hello' function that returns greetings in English, Spanish, French, and German. It utilizes sub-tests in Go's testing framework to ensure correctness for various inputs and languages. The function handles empty names by defaulting to 'World'. ```go package main import "fmt" const helloPrefix = "Hello, " const spanishPrefix = "Hola, " const frenchPrefix = "Bonjour, " const germanPrefix = "Hallo, " const spanish = "Spanish" const french = "French" const german = "German" // Hello returns a greeting in the specified language func Hello(name, language string) string { if name == "" { name = "World" } switch language { case spanish: return spanishPrefix + name case french: return frenchPrefix + name case german: return germanPrefix + name } return helloPrefix + name } func main() { fmt.Println(Hello("Rohan", "English")) // Output: Hello, Rohan fmt.Println(Hello("Raul", "Spanish")) // Output: Hola, Raul } // Comprehensive test with sub-tests func TestHello(t *testing.T) { assertCorrectMessage := func(t *testing.T, got, want string) { t.Helper() if got != want { t.Errorf("got '%s' want '%s'", got, want) } } t.Run("saying hello to people", func(t *testing.T) { got := Hello("Rohan", "") want := "Hello, Rohan" assertCorrectMessage(t, got, want) }) t.Run("say 'Hello, World' when an empty string is supplied", func(t *testing.T) { got := Hello("", "") want := "Hello, World" assertCorrectMessage(t, got, want) }) t.Run("in Spanish", func(t *testing.T) { got := Hello("Raul", "Spanish") want := "Hola, Raul" assertCorrectMessage(t, got, want) }) t.Run("in French", func(t *testing.T) { got := Hello("Zaltan", "French") want := "Bonjour, Zaltan" assertCorrectMessage(t, got, want) }) t.Run("in German", func(t *testing.T) { got := Hello("Ludwig", "German") want := "Hallo, Ludwig" assertCorrectMessage(t, got, want) }) } // Run: go test -v ``` -------------------------------- ### Wallet Operations with Pointers and Error Handling in Go Source: https://context7.com/veilair/test-driven-development/llms.txt Implements a Bitcoin wallet with deposit, balance, and withdrawal functionalities. It utilizes pointers for the Wallet type and custom error handling for insufficient funds. The code includes a test function to verify these operations. ```go package Fintech import ( "errors" "fmt" ) type Bitcoin int type Wallet struct { balance Bitcoin } var ErrInsufficientFunds = errors.New("cannot withdraw, insufficient funds") func (b Bitcoin) String() string { return fmt.Sprintf("%d BTC", b) } func (w *Wallet) Deposit(amount Bitcoin) { w.balance += amount } func (w *Wallet) Balance() Bitcoin { return w.balance } func (w *Wallet) Withdraw(amount Bitcoin) error { if amount > w.balance { return ErrInsufficientFunds } w.balance -= amount return nil } func TestWallet(t *testing.T) { assertBalance := func(t *testing.T, wallet Wallet, want Bitcoin) { t.Helper() got := wallet.Balance() if got != want { t.Errorf("got %s want %s", got, want) } } assertError := func(t *testing.T, got error, want error) { t.Helper() if got == nil { t.Error("didn't get an error but wanted one") } if got.Error() != want.Error() { t.Errorf("got '%s', want '%s'", got, want) } } assertNoError := func(t *testing.T, got error) { t.Helper() if got != nil { t.Fatal("got an error but didn't want one") } } t.Run("Deposit", func(t *testing.T) { wallet := Wallet{} wallet.Deposit(10) assertBalance(t, wallet, Bitcoin(10)) }) t.Run("Withdraw with Funds", func(t *testing.T) { wallet := Wallet{balance: Bitcoin(20)} err := wallet.Withdraw(Bitcoin(10)) assertBalance(t, wallet, Bitcoin(10)) assertNoError(t, err) }) t.Run("Withdraw insufficient funds", func(t *testing.T) { startingBalance := Bitcoin(20) wallet := Wallet{startingBalance} err := wallet.Withdraw(Bitcoin(100)) assertBalance(t, wallet, startingBalance) assertError(t, err, ErrInsufficientFunds) }) } // Run: go test -v ``` -------------------------------- ### Go Shape Interface and Structs for Area Calculation Source: https://context7.com/veilair/test-driven-development/llms.txt Defines a Shape interface with an Area() method and concrete structs (Rectangle, Circle, Triangle) that implement this interface. This enables polymorphic behavior for calculating the area of different geometric shapes. The code includes methods for calculating area and perimeter for Rectangle, area for Circle, and area for Triangle. ```go package shapes import "math" type Rectangle struct { Width float64 Height float64 } type Circle struct { Radius float64 } type Triangle struct { Base float64 Height float64 } // Shape interface for polymorphic area calculation type Shape interface { Area() float64 } func (rectangle Rectangle) Perimeter() float64 { return 2 * (rectangle.Width + rectangle.Height) } func (rectangle Rectangle) Area() float64 { return rectangle.Width * rectangle.Height } func (circle Circle) Area() float64 { return math.Pi * math.Pow(circle.Radius, 2) } func (t Triangle) Area() float64 { return (t.Base * t.Height) * 0.5 } ``` -------------------------------- ### Go Test for Rectangle Perimeter Calculation Source: https://context7.com/veilair/test-driven-development/llms.txt Provides a Go test function to verify the Perimeter() method for a Rectangle struct. It instantiates a Rectangle, calls its Perimeter() method, and asserts that the returned value matches the expected perimeter. This demonstrates testing a specific method on a concrete struct. ```go func TestPerimeter(t *testing.T) { rectangle := Rectangle{10.0, 40.0} got := rectangle.Perimeter() want := 100.0 if got != want { t.Errorf("got %.2f want %.2f", got, want) } } // Run: go test -v ``` -------------------------------- ### Go Dictionary CRUD Operations and Custom Errors Source: https://context7.com/veilair/test-driven-development/llms.txt Implements a dictionary using Go maps with custom error types for CRUD operations. Supports adding, searching, updating, and deleting words, with specific error handling for non-existent words or duplicate entries. Includes helper functions for testing. ```go package maps import "testing" // Dictionary type based on Go map type Dictionary map[string]string const ( ErrNotFound = DictionaryErr("could not find the word you were looking for") ErrWordExists = DictionaryErr("cannot add word because it already exists") ErrWordDoesNotExist = DictionaryErr("cannot update word because it does not exist") ) // DictionaryErr custom error type type DictionaryErr string func (e DictionaryErr) Error() string { return string(e) } // SearchV2 looks up a word in the dictionary func (d Dictionary) SearchV2(word string) (string, error) { definition, ok := d[word] if !ok { return "", ErrNotFound } return definition, nil } // Add adds a new word to the dictionary func (d Dictionary) Add(word, definition string) error { _, err := d.SearchV2(word) switch err { case ErrNotFound: d[word] = definition case nil: return ErrWordExists default: return err } return nil } // Update modifies an existing word's definition func (d Dictionary) Update(word, definition string) error { _, err := d.SearchV2(word) switch err { case ErrNotFound: return ErrWordDoesNotExist case nil: d[word] = definition default: return err } return nil } // Delete removes a word from the dictionary func (d Dictionary) Delete(word string) { delete(d, word) } // Test helpers func assertString(t *testing.T, got string, want string) { t.Helper() if got != want { t.Errorf("Expected: %s, Wanted: %s", want, got) } } func assertError(t *testing.T, got, want error) { t.Helper() if got != want { t.Errorf("got error '%s' want '%s'", got, want) } } func assertDefinition(t *testing.T, dictionary Dictionary, word, def string) { t.Helper() got, err := dictionary.SearchV2(word) if err != nil { t.Fatalf("Should search for an added word: %s", err) } if def != got { t.Errorf("Got: %s, Want: %s", got, def) } } func TestSearchV2(t *testing.T) { dictionary := Dictionary{"test": "This is a type test"} t.Run("Known Word", func(t *testing.T) { got, _ := dictionary.SearchV2("test") want := "This is a type test" assertString(t, got, want) }) t.Run("Unknown word", func(t *testing.T) { _, got := dictionary.SearchV2("unknown") assertError(t, got, ErrNotFound) }) } func TestAdd(t *testing.T) { t.Run("new word", func(t *testing.T) { dictionary := Dictionary{} word := "hot" def := "having a high degree of heat or a high temperature" err := dictionary.Add(word, def) assertError(t, err, nil) assertDefinition(t, dictionary, word, def) }) t.Run("existing word", func(t *testing.T) { word := "hot" def := "having a high degree of heat or a high temperature" dictionary := Dictionary{word: def} err := dictionary.Add(word, "new test") assertError(t, err, ErrWordExists) assertDefinition(t, dictionary, word, def) }) } func TestDelete(t *testing.T) { word := "test" dictionary := Dictionary{word: "test definition"} dictionary.Delete(word) _, err := dictionary.SearchV2(word) if err != ErrNotFound { t.Errorf("Expected '%s' to be deleted", word) } } // Run: go test -v ``` -------------------------------- ### Go Table-Driven Tests for Shape Area Source: https://context7.com/veilair/test-driven-development/llms.txt Implements table-driven tests in Go to verify the Area() method for various shapes (Rectangle, Circle, Triangle). This approach uses a slice of structs to define test cases, making it easy to add or modify tests. The tests check if the calculated area matches the expected value. ```go // Table-driven tests for multiple shapes func TestArea(t *testing.T) { areaTests := []struct { name string shape Shape hasArea float64 }{ {name: "Rectangle", shape: Rectangle{Width: 12, Height: 6}, hasArea: 72.0}, {name: "Circle", shape: Circle{Radius: 10}, hasArea: 314.1592653589793}, {name: "Triangle", shape: Triangle{Base: 15, Height: 6}, hasArea: 45.0}, } t.Run("Table Driven Tests", func(t *testing.T) { for _, tt := range areaTests { got := tt.shape.Area() if got != tt.hasArea { t.Errorf("got %.2f want %.2f", got, tt.hasArea) } } }) } ``` -------------------------------- ### Amending the Most Recent Commit Source: https://github.com/veilair/test-driven-development/blob/main/contributing.md This snippet illustrates how to amend the latest commit with new changes, typically used for minor corrections or additions before a pull request is reviewed. ```shell git add . git commit --amend git push --force-with-lease origin my-new-feature ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.