decred.org/dcrdex@v1.0.5/dex/bip-id_test.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org/license/1.0.0.
     3  
     4  package dex
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestBipIDSymbol(t *testing.T) {
    11  	tests := []struct {
    12  		name string
    13  		idx  uint32
    14  		want string
    15  	}{
    16  		{
    17  			name: "ok",
    18  			idx:  42,
    19  			want: "dcr",
    20  		},
    21  		{
    22  			name: "missing",
    23  			idx:  111111111,
    24  			want: "",
    25  		},
    26  	}
    27  	for _, tt := range tests {
    28  		t.Run(tt.name, func(t *testing.T) {
    29  			if got := BipIDSymbol(tt.idx); got != tt.want {
    30  				t.Errorf("BipIDSymbol() = %v, want %v", got, tt.want)
    31  			}
    32  		})
    33  	}
    34  }
    35  
    36  func TestBipSymbolID(t *testing.T) {
    37  	tests := []struct {
    38  		name   string
    39  		symbol string
    40  		want   uint32
    41  		want1  bool
    42  	}{
    43  		{
    44  			name:   "ok",
    45  			symbol: "dcr",
    46  			want:   42,
    47  			want1:  true,
    48  		},
    49  		{
    50  			name:   "ok, again with pre-computed map",
    51  			symbol: "dcr",
    52  			want:   42,
    53  			want1:  true,
    54  		},
    55  		{
    56  			name:   "missing",
    57  			symbol: "blahblahfake",
    58  			want:   0,
    59  			want1:  false,
    60  		},
    61  	}
    62  	for _, tt := range tests {
    63  		t.Run(tt.name, func(t *testing.T) {
    64  			got, got1 := BipSymbolID(tt.symbol)
    65  			if got != tt.want {
    66  				t.Errorf("BipSymbolID() got = %v, want %v", got, tt.want)
    67  			}
    68  			if got1 != tt.want1 {
    69  				t.Errorf("BipSymbolID() got1 = %v, want %v", got1, tt.want1)
    70  			}
    71  		})
    72  	}
    73  }