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.119 tracks/go/exercises/counter/example.go
trackler-2.2.1.118 tracks/go/exercises/counter/example.go
trackler-2.2.1.117 tracks/go/exercises/counter/example.go
trackler-2.2.1.116 tracks/go/exercises/counter/example.go
trackler-2.2.1.115 tracks/go/exercises/counter/example.go
trackler-2.2.1.114 tracks/go/exercises/counter/example.go
trackler-2.2.1.113 tracks/go/exercises/counter/example.go
trackler-2.2.1.111 tracks/go/exercises/counter/example.go
trackler-2.2.1.110 tracks/go/exercises/counter/example.go
trackler-2.2.1.109 tracks/go/exercises/counter/example.go
trackler-2.2.1.108 tracks/go/exercises/counter/example.go
trackler-2.2.1.107 tracks/go/exercises/counter/example.go
trackler-2.2.1.106 tracks/go/exercises/counter/example.go
trackler-2.2.1.105 tracks/go/exercises/counter/example.go
trackler-2.2.1.104 tracks/go/exercises/counter/example.go
trackler-2.2.1.103 tracks/go/exercises/counter/example.go
trackler-2.2.1.102 tracks/go/exercises/counter/example.go
trackler-2.2.1.101 tracks/go/exercises/counter/example.go
trackler-2.2.1.100 tracks/go/exercises/counter/example.go
trackler-2.2.1.99 tracks/go/exercises/counter/example.go