Skip to content

Commit

Permalink
better tests and method fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vocatart committed Nov 29, 2024
1 parent d7dd6b8 commit f2c08d3
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 186 deletions.
105 changes: 19 additions & 86 deletions htk/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,33 @@ package htk

import "testing"

func TestGettingAnnotationDuration(t *testing.T) {
// loading the first annotation from the first example as a dummy annotation
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
}

annotation := lab.annotations[0]
trueDuration := annotation.end - annotation.start
func TestCreatingAnnotation(t *testing.T) {
annotation := Annotation{0.0, 10.0, "test"}

if annotation.GetDuration() != trueDuration {
t.Fatalf("wanted duration %f, received %f", trueDuration, annotation.GetDuration())
if annotation.GetStart() != 0.0 {
t.Errorf("expected 0.0, got %f", annotation.GetStart())
}

t.Log("Getting annotation duration successful!")
}

func TestGettingAnnotationStart(t *testing.T) {
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
if annotation.GetEnd() != 10.0 {
t.Errorf("expected 10.0, got %f", annotation.GetEnd())
}

annotation := lab.annotations[0]
trueStart := annotation.start

if annotation.GetStart() != trueStart {
t.Fatalf("wanted start time of %f, received %f", trueStart, annotation.GetStart())
if annotation.GetLabel() != "test" {
t.Errorf("expected test, got %s", annotation.GetLabel())
}

t.Log("getting annotation start successful!")
}

func TestGettingAnnotationEnd(t *testing.T) {
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
if annotation.GetDuration() != 10.0 {
t.Errorf("expected 10.0, got %f", annotation.GetDuration())
}

annotation := lab.annotations[0]
trueEnd := annotation.end
annotation.SetStart(15.0)
annotation.SetEnd(20.0)
annotation.SetLabel("test2")

if annotation.GetEnd() != trueEnd {
t.Fatalf("wanted end time of %f, received %f", trueEnd, annotation.GetEnd())
if annotation.GetStart() != 15.0 {
t.Errorf("expected 15.0, got %f", annotation.GetStart())
}

t.Log("getting annotation end successful!")
}

func TestGettingAnnotationLabel(t *testing.T) {
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
if annotation.GetEnd() != 20.0 {
t.Errorf("expected 20.0, got %f", annotation.GetEnd())
}

annotation := lab.annotations[0]
trueLabel := annotation.label

if annotation.GetLabel() != trueLabel {
t.Fatalf("wanted label %s, received %s", trueLabel, annotation.GetLabel())
}

t.Log("test setting annotation label successful!")
}

func TestSettingAnnotationStartEnd(t *testing.T) {
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
}

annotation := lab.annotations[0]
annotation.SetStart(10)
annotation.SetEnd(20)

if annotation.start != 10 {
t.Fatalf("wanted start time of 10, received %f", annotation.start)
} else if annotation.end != 20 {
t.Fatalf("wanted end time of 20, received %f", annotation.end)
}

t.Log("setting annotation start and end successful!")
}

func TestSettingAnnotationLabel(t *testing.T) {
lab, err := ReadLab("examples/01.lab")
if err != nil {
t.Fatal(err)
}

annotation := lab.annotations[0]
annotation.SetLabel("label")

if annotation.label != "label" {
t.Fatalf("wanted label string of \"label\", recieved %s", annotation.label)
if annotation.GetLabel() != "test2" {
t.Errorf("expected test2, got %s", annotation.GetLabel())
}
}
60 changes: 13 additions & 47 deletions htk/lab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ func TestReadingLab(t *testing.T) {
t.Fatal(err)
}

if lab.name != "short.lab" {
t.Fatalf("wanted 'short', recieved %s", lab.name)
} else if lab.annotations == nil {
if lab.GetName() != "short.lab" {
t.Fatalf("wanted 'short', recieved %s", lab.GetName())
} else if lab.GetAnnotations() == nil {
t.Fatalf("wanted annotations, recieved nil")
} else if lab.precision != 7 {
t.Fatalf("wanted precision of 7, recieved %d", lab.precision)
} else if lab.GetPrecision() != 7 {
t.Fatalf("wanted precision of 7, recieved %d", lab.GetPrecision())
}

t.Log("lab reading successful!")
}

func TestReadingDifferentPrecision(t *testing.T) {
Expand All @@ -25,11 +23,9 @@ func TestReadingDifferentPrecision(t *testing.T) {
t.Fatal(err)
}

if lab.precision != 6 {
t.Fatalf("wanted precision of 6, recieved %d", lab.precision)
if lab.GetPrecision() != 6 {
t.Fatalf("wanted precision of 6, recieved %d", lab.GetPrecision())
}

t.Log("different precisions reading successful!")
}

func TestWritingLab(t *testing.T) {
Expand All @@ -42,8 +38,6 @@ func TestWritingLab(t *testing.T) {
if err != nil {
return
}

t.Log("lab writing successful!")
}

func TestWritingDifferentPrecision(t *testing.T) {
Expand All @@ -56,8 +50,6 @@ func TestWritingDifferentPrecision(t *testing.T) {
if err != nil {
return
}

t.Log("different precision writing successful!")
}

func TestPrintingLabString(t *testing.T) {
Expand All @@ -69,8 +61,6 @@ func TestPrintingLabString(t *testing.T) {
if lab.ToString() != "0.0000000 10.0000000 test\n" {
t.Fatal("malformed lab string!")
}

t.Log("printing lab to string successful!")
}

func TestSettingAnnotations(t *testing.T) {
Expand All @@ -84,8 +74,6 @@ func TestSettingAnnotations(t *testing.T) {
if lab.ToString() != "0 1 test1\n1 2 test2\n2 3 test3\n" {
t.Fatal("annotations not set correctly!")
}

t.Log("setting annotations successful!")
}

func TestGettingAnnotations(t *testing.T) {
Expand All @@ -94,15 +82,13 @@ func TestGettingAnnotations(t *testing.T) {
t.Fatal(err)
}

if lab.annotations[0].start != 0 {
t.Fatalf("incorrect annotation start time! wanted 0, recieved %f", lab.annotations[0].start)
} else if lab.annotations[0].end != 10 {
t.Fatalf("incorrect annotation end time! wanted 10, recieved %f", lab.annotations[0].end)
} else if lab.annotations[0].label != "test" {
t.Fatalf("incorrect annotation label!, wanted string \"test\", recieved string \"%s\"", lab.annotations[0].label)
if lab.GetAnnotations()[0].GetStart() != 0 {
t.Fatalf("incorrect annotation start time! wanted 0, recieved %f", lab.GetAnnotations()[0].GetStart())
} else if lab.GetAnnotations()[0].GetEnd() != 10 {
t.Fatalf("incorrect annotation end time! wanted 10, recieved %f", lab.GetAnnotations()[0].GetEnd())
} else if lab.GetAnnotations()[0].GetLabel() != "test" {
t.Fatalf("incorrect annotation label!, wanted string \"test\", recieved string \"%s\"", lab.GetAnnotations()[0].GetLabel())
}

t.Log("getting annotations successful!")
}

func TestPushingAnnotation(t *testing.T) {
Expand All @@ -120,8 +106,6 @@ func TestPushingAnnotation(t *testing.T) {
} else if lab.annotations[2].end != 30 {
t.Fatalf("incorrect annotation end time! wanted end time 30, recieved %f", lab.annotations[2].end)
}

t.Log("pushing annotations successful!")
}

func TestAppendingAnnotations(t *testing.T) {
Expand Down Expand Up @@ -150,8 +134,6 @@ func TestAppendingAnnotations(t *testing.T) {
} else if lab.annotations[3].label != "new_annotation2" {
t.Fatalf("incorrect annotation label!")
}

t.Log("appending annotations successful!")
}

func TestClearingAnnotations(t *testing.T) {
Expand All @@ -165,8 +147,6 @@ func TestClearingAnnotations(t *testing.T) {
if lab.ToString() != "" {
t.Fatal("lab not properly cleared!")
}

t.Log("clearing annotations successful!")
}

func TestDumpingLabels(t *testing.T) {
Expand All @@ -181,8 +161,6 @@ func TestDumpingLabels(t *testing.T) {
if isEqualSlice(labSlice, groundTruthSlice) == false {
t.Fatal("returned slices not identical!")
}

t.Log("annotation dumping successful!")
}

func TestGettingLabName(t *testing.T) {
Expand All @@ -194,8 +172,6 @@ func TestGettingLabName(t *testing.T) {
if lab.GetName() != lab.name {
t.Fatalf("wanted lab name %s, recieved %s", lab.name, lab.GetName())
}

t.Log("getting lab name successful!")
}

func TestSettingLabName(t *testing.T) {
Expand All @@ -209,8 +185,6 @@ func TestSettingLabName(t *testing.T) {
if lab.name != "newName" {
t.Fatalf("wanted lab name of \"newName\", recieved \"%s\"", lab.name)
}

t.Log("setting lab name successful!")
}

func TestGettingPrecision(t *testing.T) {
Expand All @@ -222,8 +196,6 @@ func TestGettingPrecision(t *testing.T) {
if lab.GetPrecision() != lab.precision {
t.Fatalf("wanted precision %d, recieved %d", lab.precision, lab.GetPrecision())
}

t.Log("getting precision successful!")
}

func TestSettingPrecision(t *testing.T) {
Expand All @@ -242,8 +214,6 @@ func TestSettingPrecision(t *testing.T) {
if err != nil {
return
}

t.Log("setting precision successful!")
}

func TestGettingLabDuration(t *testing.T) {
Expand All @@ -257,8 +227,6 @@ func TestGettingLabDuration(t *testing.T) {
if lab.GetDuration() != trueDuration {
t.Fatalf("wanted duration of %f, recieved %f", trueDuration, lab.GetDuration())
}

t.Log("getting lab duration successful!")
}

func TestGettingLabLength(t *testing.T) {
Expand All @@ -272,6 +240,4 @@ func TestGettingLabLength(t *testing.T) {
if lab.GetLength() != trueLength {
t.Fatalf("wanted length of %d, recieved %d", trueLength, lab.GetLength())
}

t.Log("getting lab length successful!")
}
36 changes: 28 additions & 8 deletions textgrid/interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,37 @@ import "testing"
func TestCreatingInterval(t *testing.T) {
interval := Interval{xmin: 0.0, xmax: 1.0, text: "test"}

if interval.xmin != 0.0 {
t.Errorf("Expected 0.0, got %f", interval.xmin)
// testing accessors
if interval.GetXmin() != 0.0 {
t.Errorf("Expected xmin 0.0, got %f", interval.xmin)
}
if interval.xmax != 1.0 {
t.Errorf("Expected 1.0, got %f", interval.xmax)
if interval.GetXmax() != 1.0 {
t.Errorf("Expected xmax 1.0, got %f", interval.xmax)
}
if interval.text != "test" {
t.Errorf("Expected 'test', got %s", interval.text)
if interval.GetText() != "test" {
t.Errorf("Expected interval label \"test\", got %q", interval.text)
}

if !t.Failed() {
t.Logf("interval created successfully")
// testing mutators
interval.SetXmin(2.0)
interval.SetXmax(3.0)
interval.SetText("test2")

if interval.GetXmin() != 2.0 {
t.Errorf("Expected xmin 2.0, got %f", interval.xmin)
}
if interval.GetXmax() != 3.0 {
t.Errorf("Expected xmax 3.0, got %f", interval.xmax)
}
if interval.GetText() != "test2" {
t.Errorf("Expected interval label \"test2\", got %q", interval.text)
}

// testing misc methods
if interval.GetDuration() != 1.0 {
t.Errorf("Expected dur of 1.0, got %f", interval.GetDuration())
}
if interval.GetMedian() != 2.5 {
t.Errorf("Expected median of 2.5, got %f", interval.GetMedian())
}
}
16 changes: 12 additions & 4 deletions textgrid/point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import "testing"
func TestCreatingPoint(t *testing.T) {
point := Point{mark: "point", value: 10.0}

if point.value != 10.0 {
// testing accessors
if point.GetValue() != 10.0 {
t.Errorf("Expected 10.0, got %f", point.value)
}
if point.mark != "point" {
if point.GetMark() != "point" {
t.Errorf("Expected 'mark', got %s", point.mark)
}

if !t.Failed() {
t.Logf("point created successfully")
// testing mutators
point.SetValue(15.0)
point.SetMark("test")

if point.GetValue() != 15.0 {
t.Errorf("Expected 15.0, got %f", point.value)
}
if point.GetMark() != "test" {
t.Errorf("Expected 'mark', got %s", point.mark)
}
}
Loading

0 comments on commit f2c08d3

Please sign in to comment.