github.com/blend/go-sdk@v1.20220411.3/timeutil/min_max_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package timeutil
     9  
    10  import (
    11  	"testing"
    12  	"time"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  )
    16  
    17  func TestMinMax(t *testing.T) {
    18  	assert := assert.New(t)
    19  	values := []time.Time{
    20  		time.Now().AddDate(0, 0, -1),
    21  		time.Now().AddDate(0, 0, -2),
    22  		time.Now().AddDate(0, 0, -3),
    23  		time.Now().AddDate(0, 0, -4),
    24  	}
    25  	min, max := MinMax(values...)
    26  	assert.Equal(values[3], min)
    27  	assert.Equal(values[0], max)
    28  }
    29  
    30  func TestMinMaxReversed(t *testing.T) {
    31  	assert := assert.New(t)
    32  	values := []time.Time{
    33  		time.Now().AddDate(0, 0, -4),
    34  		time.Now().AddDate(0, 0, -2),
    35  		time.Now().AddDate(0, 0, -3),
    36  		time.Now().AddDate(0, 0, -1),
    37  	}
    38  	min, max := MinMax(values...)
    39  	assert.Equal(values[0], min)
    40  	assert.Equal(values[3], max)
    41  }
    42  
    43  func TestMinMaxEmpty(t *testing.T) {
    44  	assert := assert.New(t)
    45  	values := []time.Time{}
    46  	min, max := MinMax(values...)
    47  	assert.Equal(time.Time{}, min)
    48  	assert.Equal(time.Time{}, max)
    49  }