Sha256: 4425b9600e13dd86e77a4577a6711749410cac5ea41f8c7b3bd08851db6017aa

Contents?: true

Size: 1.92 KB

Versions: 396

Compression:

Stored size: 1.92 KB

Contents

package counter

// NOTE: This file is called example.go and not example_test.go because if it's
// called example_test.go it will get picked up by the test suite and fail
// because COUNTER_IMPL isn't set (see maker.go).

import "testing"

func TestNoAdd(t *testing.T) {
	counter := makeCounter()
	if counter.Lines() != 0 {
		t.Errorf("Lines mismatch: got %d, expected %d", counter.Lines(), 0)
	}
	if counter.Letters() != 0 {
		t.Errorf("Letters mismatch: got %d, expected %d", counter.Letters(), 0)
	}
	if counter.Characters() != 0 {
		t.Errorf("Characters mismatch: got %d, expected %d", counter.Characters(), 0)
	}
}

func TestEmptyString(t *testing.T) {
	counter := makeCounter()
	counter.AddString("")
	if counter.Lines() != 0 {
		t.Errorf("Lines mismatch: got %d, expected %d", counter.Lines(), 0)
	}
	if counter.Letters() != 0 {
		t.Errorf("Letters mismatch: got %d, expected %d", counter.Letters(), 0)
	}
	if counter.Characters() != 0 {
		t.Errorf("Characters mismatch: got %d, expected %d", counter.Characters(), 0)
	}
}

func TestASCIIString(t *testing.T) {
	counter := makeCounter()
	counter.AddString("Hello\nworld!")
	if counter.Lines() != 2 {
		t.Errorf("Lines mismatch: got %d, expected %d", counter.Lines(), 2)
	}
	if counter.Letters() != 10 {
		t.Errorf("Letters mismatch: got %d, expected %d", counter.Letters(), 10)
	}
	if counter.Characters() != 12 {
		t.Errorf("Characters mismatch: got %d, expected %d", counter.Characters(), 12)
	}
}

func TestRussianString(t *testing.T) {
	counter := makeCounter()
	// Lifted this translation from the ru.po file of GNU hello
	counter.AddString("здравствуй, мир\n")
	if counter.Lines() != 1 {
		t.Errorf("Lines mismatch: got %d, expected %d", counter.Lines(), 2)
	}
	if counter.Letters() != 13 {
		t.Errorf("Letters mismatch: got %d, expected %d", counter.Letters(), 10)
	}
	if counter.Characters() != 16 {
		t.Errorf("Characters mismatch: got %d, expected %d", counter.Characters(), 12)
	}
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/counter/example.go
trackler-2.2.1.179 tracks/go/exercises/counter/example.go
trackler-2.2.1.178 tracks/go/exercises/counter/example.go
trackler-2.2.1.177 tracks/go/exercises/counter/example.go
trackler-2.2.1.176 tracks/go/exercises/counter/example.go
trackler-2.2.1.175 tracks/go/exercises/counter/example.go
trackler-2.2.1.174 tracks/go/exercises/counter/example.go
trackler-2.2.1.173 tracks/go/exercises/counter/example.go
trackler-2.2.1.172 tracks/go/exercises/counter/example.go
trackler-2.2.1.171 tracks/go/exercises/counter/example.go
trackler-2.2.1.170 tracks/go/exercises/counter/example.go
trackler-2.2.1.169 tracks/go/exercises/counter/example.go
trackler-2.2.1.167 tracks/go/exercises/counter/example.go
trackler-2.2.1.166 tracks/go/exercises/counter/example.go
trackler-2.2.1.165 tracks/go/exercises/counter/example.go
trackler-2.2.1.164 tracks/go/exercises/counter/example.go
trackler-2.2.1.163 tracks/go/exercises/counter/example.go
trackler-2.2.1.162 tracks/go/exercises/counter/example.go
trackler-2.2.1.161 tracks/go/exercises/counter/example.go
trackler-2.2.1.160 tracks/go/exercises/counter/example.go