package main

import (
	"os"
	"testing"
)

func TestNewDeck(t *testing.T) {
	d := newDeck()

	if len(d) != 52 {
		t.Errorf("Expected deck length of 52, but got %d", len(d))
	}

	if d[0] != "Ace of Spades" {
		t.Errorf("Expected the first card to be Ace of Spades, but got %s", d[0])
	}

	if d[len(d)-1] != "King of Clubs" {
		t.Errorf("Expected the first card to be King of Clubs, but got %s", d[len(d)-1])
	}
}

func TestSaveDeckToDiskAndLoadDeckFromDisk(t *testing.T) {
	os.Remove("_decktesting")
	d := newDeck()

	r_err := d.saveToFile("_decktesting")
	if r_err != nil {
		t.Errorf("Failed to save file to _decktesting, got error: %s", r_err)
	}
	r := newDeckFromFile("_decktesting")
	if r.toString() != d.toString() {
		t.Errorf("Failed to load deck, contents does not match")
	}

	os.Remove("_decktesting")

}
