Files
utils/utils_test.go
zeekayandHanzo Dev ac0def4322 the corporate name is Lux Industries Inc
Lux Partners Limited is not the entity behind this work. Every place the
old name stood — copyright lines, site footers, brand config, legal and
compliance text — now names the company that actually holds it.

lux.fund is the exception and is not renamed to match: that site belongs
to Lux Assets Management LLC, a different company, and it says so.

Two kinds of line were left for a person rather than rewritten. A dated
news item recording that Lux Partners Limited was established in the Isle
of Man is a historical fact, and renaming it would falsify the record. And
a sentence asserting that the company is domiciled in the Isle of Man is a
claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle
of Man company, so swapping the name there would assert something untrue.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-28 11:07:38 -07:00

121 lines
2.9 KiB
Go

// Copyright (C) 2025, Lux Industries Inc All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"testing"
"time"
"github.com/luxfi/constants"
"github.com/stretchr/testify/require"
)
func TestUnique(t *testing.T) {
// empty
input := []int{}
expected := []int{}
result := Unique(input)
require.Equal(t, expected, result)
// ordered input
input = []int{1, 2, 2, 3, 4, 4, 5}
expected = []int{1, 2, 3, 4, 5}
result = Unique(input)
require.Equal(t, expected, result)
// unordered input
input = []int{5, 2, 1, 3, 4, 2, 4}
expected = []int{5, 2, 1, 3, 4}
result = Unique(input)
require.Equal(t, expected, result)
}
func TestBelongs(t *testing.T) {
// empty
input := []string{}
require.False(t, Belongs(input, "orange"))
// non empty
input = []string{"apple", "banana", "cherry"}
require.True(t, Belongs(input, "banana"))
require.False(t, Belongs(input, "orange"))
}
func TestUint32Sort(t *testing.T) {
// empty
input := []uint32{}
expected := []uint32{}
Uint32Sort(input)
require.Equal(t, expected, input)
// non empty
input = []uint32{5, 3, 4, 1, 2}
expected = []uint32{1, 2, 3, 4, 5}
Uint32Sort(input)
require.Equal(t, expected, input)
}
func TestGetAPIContext(t *testing.T) {
ctx, cancel := GetAPIContext()
deadline, hasDeadline := ctx.Deadline()
timeout := time.Until(deadline)
select {
case <-ctx.Done():
// Context should not be done immediately
t.Fatal("context should not be done immediately")
default:
// Context is still active
}
require.Equal(t, true, hasDeadline)
require.Equal(t, true, timeout-constants.APIRequestTimeout < time.Millisecond)
cancel()
select {
case <-ctx.Done():
// Context should be done immediately
default:
// Context is still active
t.Fatal("context should be done immediately")
}
}
func TestGetAPILargeContext(t *testing.T) {
ctx, cancel := GetAPILargeContext()
deadline, hasDeadline := ctx.Deadline()
timeout := time.Until(deadline)
select {
case <-ctx.Done():
// Context should not be done immediately
t.Fatal("context should not be done immediately")
default:
// Context is still active
}
require.Equal(t, true, hasDeadline)
require.Equal(t, true, timeout-constants.APIRequestLargeTimeout < time.Millisecond)
cancel()
select {
case <-ctx.Done():
// Context should be done immediately
default:
// Context is still active
t.Fatal("context should be done immediately")
}
}
func TestGetTimedContext(t *testing.T) {
timeout := 50 * time.Millisecond
ctx, cancel := GetTimedContext(timeout)
defer cancel()
select {
case <-ctx.Done():
// Context should not be done immediately
t.Fatal("context should not be done immediately")
default:
// Context is still active
}
time.Sleep(timeout)
time.Sleep(1 * time.Millisecond)
select {
case <-ctx.Done():
// Context should be done after timeout
default:
t.Fatal("context should be done after timeout")
}
}