NoPaste

manperf_test.go

von paedubucher
SNIPPET_DESC:
Tests für manperf.go
SNIPPET_CREATION_TIME:
19.06.2022 17:21:12
SNIPPET_PRUNE_TIME:
Unendlich

SNIPPET_TEXT:
  1. package dfdegoregexp
  2.  
  3. import (
  4.         "testing"
  5. )
  6.  
  7. var expectedSections = []string{"NAME", "SYNOPSIS", "DESCRIPTION", "EXAMPLES",
  8.         "OVERVIEW", "DEFAULTS", "OPTIONS", "EXIT STATUS", "ENVIRONMENT", "FILES",
  9.         "SEE ALSO", "HISTORY"}
  10.  
  11. func TestExtractSectionsBad(t *testing.T) {
  12.         lines := CommandOutput("man", "man")
  13.         actual := ExtractSectionsBad(lines)
  14.         for i, e := range expectedSections {
  15.                 if actual[i] != e {
  16.                         t.Errorf("expected actual[%d]==%s, was %s", i, e, actual[i])
  17.                 }
  18.         }
  19. }
  20.  
  21. func TestExtractSectionsBetter(t *testing.T) {
  22.         lines := CommandOutput("man", "man")
  23.         actual := ExtractSectionsBetter(lines)
  24.         for i, e := range expectedSections {
  25.                 if actual[i] != e {
  26.                         t.Errorf("expected actual[%d]==%s, was %s", i, e, actual[i])
  27.                 }
  28.         }
  29. }
  30.  
  31. func BenchmarkExtractSectionsBad(b *testing.B) {
  32.         b.StopTimer()
  33.         lines := CommandOutput("man", "man")
  34.         b.StartTimer()
  35.         for i := 0; i < b.N; i++ {
  36.                 ExtractSectionsBad(lines)
  37.         }
  38. }
  39.  
  40. func BenchmarkExtractSectionsBetter(b *testing.B) {
  41.         b.StopTimer()
  42.         lines := CommandOutput("man", "man")
  43.         b.StartTimer()
  44.         for i := 0; i < b.N; i++ {
  45.                 ExtractSectionsBetter(lines)
  46.         }
  47. }

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN