Commit cd69af19 authored by Muhammad, Hammad's avatar Muhammad, Hammad

added unit_test cases

parent a853f759
package main
import (
"os"
"testing"
)
func TestNewDeck(t *testing.T) {
d := newDeck()
if len(d) != 16 {
t.Errorf("Expected deck length of 16, but got %v", len(d))
}
if d[0] != "Ace of Spades" {
t.Errorf("Expected first card of Ace of Spades, but got %v", d[0])
}
if d[len(d)-1] != "Four of Clubs" {
t.Errorf("Expected last card of Four of Clubs, but got %v", d[len(d)-1])
}
}
func TestSaveToDeckAndNewDeckFromFile(t *testing.T) {
os.Remove("_decktesting")
deck := newDeck()
deck.saveToFile("_decktesting")
loadedDeck := newDeckFromFile("_decktesting")
if len(loadedDeck) != 16 {
t.Errorf("Expected 16 cards in deck, got %v", len(loadedDeck))
}
os.Remove("_decktesting")
}
// Execute test file by this command : go test
module hello_world
go 1.20
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment