github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/workload/faker/faker_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package faker
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  	"golang.org/x/exp/rand"
    18  )
    19  
    20  func TestFaker(t *testing.T) {
    21  	rng := rand.New(rand.NewSource(0))
    22  	f := NewFaker()
    23  
    24  	names := []string{
    25  		`Daniel Nixon`,
    26  		`Whitney Jimenez`,
    27  		`Brandon Carr`,
    28  	}
    29  	for i, name := range names {
    30  		assert.Equal(t, name, f.Name(rng), `testcase %d`, i)
    31  	}
    32  
    33  	streetAddresses := []string{
    34  		`8339 Gary Burgs Apt. 6`,
    35  		`67941 Lawrence Station Suite 29`,
    36  		`29657 Ware Haven`,
    37  	}
    38  	for i, streetAddress := range streetAddresses {
    39  		assert.Equal(t, streetAddress, f.StreetAddress(rng), `testcase %d`, i)
    40  	}
    41  
    42  	wordsets := [][]string{
    43  		{`until`},
    44  		{`figure`, `after`},
    45  		{`suddenly`, `heavy`, `time`},
    46  	}
    47  	for i, words := range wordsets {
    48  		assert.Equal(t, words, f.Words(rng, i+1), `testcase %d`, i)
    49  	}
    50  
    51  	sentences := [][]string{
    52  		{
    53  			`Especially claim rather town.`,
    54  		},
    55  		{
    56  			`Bag other follow play agreement develop sing.`,
    57  			`Deal great national yard various mouth.`,
    58  		},
    59  		{
    60  			`During talk direction set clear direction.`,
    61  			`Realize once thus administration.`,
    62  			`Glass industry drop prove large age any.`,
    63  		},
    64  	}
    65  	for i, sentence := range sentences {
    66  		assert.Equal(t, sentence, f.Sentences(rng, i+1), `testcase %d`, i)
    67  	}
    68  
    69  	paragraphs := []string{
    70  		`Natural purpose member institution picture address. Goal use produce drive worry process ` +
    71  			`beautiful somebody.`,
    72  		`Stuff home capital international. Consumer message bed story here. Contain real expert ` +
    73  			`institution. Against ever seek become put respond. Maybe recently entire history always ` +
    74  			`former.`,
    75  		`Court three author ground. College walk inside coach system career newspaper. However ` +
    76  			`health me community mission. Senior evidence form size true general compare. Teacher look ` +
    77  			`left else.`,
    78  	}
    79  	for i, paragraph := range paragraphs {
    80  		assert.Equal(t, paragraph, f.Paragraph(rng), `testcase %d`, i)
    81  	}
    82  }
    83  
    84  func TestFirstToUpper(t *testing.T) {
    85  	tests := []struct {
    86  		input, expected string
    87  	}{
    88  		{`foobar`, `Foobar`},
    89  		{`fooBar`, `FooBar`},
    90  		{`foo bar`, `Foo bar`},
    91  		{`foo Bar`, `Foo Bar`},
    92  		{`κόσμε`, `Κόσμε`},
    93  	}
    94  	for i, test := range tests {
    95  		assert.Equal(t, test.expected, firstToUpper(test.input), `testcase %d`, i)
    96  	}
    97  }