go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/mathutil/normalize_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package mathutil
     9  
    10  import (
    11  	"testing"
    12  
    13  	"go.charczuk.com/sdk/assert"
    14  )
    15  
    16  func Test_Normalize(t *testing.T) {
    17  	input := []int{1, 6, 10, 25, 50}
    18  
    19  	output := Normalize(input)
    20  
    21  	assert.ItsLen(t, output, len(input))
    22  	assert.ItsEqual(t, 0, output[0])
    23  	assert.ItsEqual(t, true, output[1] > 0.102 && output[1] < 0.103, output[1])
    24  	assert.ItsEqual(t, true, output[2] > 0.183 && output[2] < 0.184, output[2])
    25  	assert.ItsEqual(t, true, output[3] > 0.489 && output[3] < 0.490)
    26  	assert.ItsEqual(t, 1, output[4])
    27  }
    28  
    29  func Test_Normalize_negatives(t *testing.T) {
    30  	input := []int{-1, -6, -10, -25, -50}
    31  
    32  	output := Normalize(input)
    33  
    34  	assert.ItsLen(t, output, len(input))
    35  	assert.ItsEqual(t, 0, output[0])
    36  	assert.ItsEqual(t, true, output[1] > 0.102 && output[1] < 0.103, output[1])
    37  	assert.ItsEqual(t, true, output[2] > 0.183 && output[2] < 0.184, output[2])
    38  	assert.ItsEqual(t, true, output[3] > 0.489 && output[3] < 0.490)
    39  	assert.ItsEqual(t, 1, output[4])
    40  }