github.com/fraugster/parquet-go@v0.12.0/floor/time_test.go (about)

     1  package floor
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestTime(t *testing.T) {
    10  	testData := []struct {
    11  		h, m, s, ns   int
    12  		expectErr     bool
    13  		expectedValue Time
    14  		expectedStr   string
    15  	}{
    16  		{h: 0, m: 0, s: 30, ns: 0, expectErr: false, expectedValue: Time{nsec: 30000000000}, expectedStr: "00:00:30"},
    17  		{h: -1, expectErr: true},
    18  		{h: 24, expectErr: true},
    19  		{m: -30, expectErr: true},
    20  		{m: 76, expectErr: true},
    21  		{s: -100, expectErr: true},
    22  		{s: 200, expectErr: true},
    23  		{ns: -1, expectErr: true},
    24  		{ns: 30000000000, expectErr: true},
    25  		{h: 13, m: 45, s: 35, expectErr: false, expectedValue: Time{nsec: 49535000000000}, expectedStr: "13:45:35"},
    26  		{h: 13, m: 45, s: 35, ns: 300, expectErr: false, expectedValue: Time{nsec: 49535000000300}, expectedStr: "13:45:35.000000300"},
    27  		{h: 13, m: 45, s: 35, ns: 300000000, expectErr: false, expectedValue: Time{nsec: 49535300000000}, expectedStr: "13:45:35.300000000"},
    28  	}
    29  
    30  	for idx, tt := range testData {
    31  		toime, err := NewTime(tt.h, tt.m, tt.s, tt.ns)
    32  		if tt.expectErr {
    33  			assert.Error(t, err, "%d. expected error but got none", idx)
    34  		} else {
    35  			assert.NoError(t, err, "%d. expected no error but got one", idx)
    36  			assert.Equal(t, tt.expectedValue, toime, "%d. doesn't match", idx)
    37  			assert.Equal(t, tt.expectedStr, toime.String(), "%d. string doesn't match", idx)
    38  			assert.Equal(t, tt.ns/1000, toime.Microsecond(), "%d. microsecond doesn't match", idx)
    39  			assert.Equal(t, tt.ns/1000000, toime.Millisecond(), "%d. millisecond doesn't match", idx)
    40  
    41  			today := toime.Today()
    42  			assert.Equal(t, tt.h, today.Hour(), "%d. hour doesn't match", idx)
    43  			assert.Equal(t, tt.m, today.Minute(), "%d. minute doesn't match", idx)
    44  			assert.Equal(t, tt.s, today.Second(), "%d. second doesn't match", idx)
    45  		}
    46  	}
    47  }