github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/print_test.go (about)

     1  // Copyright (c) 2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func TestDollars(t *testing.T) {
    13  	var tests = []struct {
    14  		cents   int64
    15  		dollars string
    16  	}{
    17  		{130000000, "$1,300,000.00"},
    18  		{13000023, "$130,000.23"},
    19  		{13000000, "$130,000.00"},
    20  		{130000, "$1,300.00"},
    21  		{13000, "$130.00"},
    22  		{78, "$0.78"},
    23  		{9, "$0.09"},
    24  		{0, "$0.00"},
    25  		{-9, "-$0.09"},
    26  		{-78, "-$0.78"},
    27  		{-13000000, "-$130,000.00"},
    28  	}
    29  	for _, tt := range tests {
    30  		testName := fmt.Sprintf("%d", tt.cents)
    31  		t.Run(testName, func(t *testing.T) {
    32  			ans := dollars(tt.cents)
    33  			if ans != tt.dollars {
    34  				t.Errorf("got '%s' want '%s'", ans, tt.dollars)
    35  			}
    36  		})
    37  	}
    38  }