tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/ds3231/ds3231_test.go (about)

     1  package ds3231
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestPositiveMilliCelsius(t *testing.T) {
     8  	t1000 := milliCelsius(0, 0)
     9  	if t1000 != 0 {
    10  		t.Fatal(t1000)
    11  	}
    12  
    13  	t1000 = milliCelsius(0, 0b01000000)
    14  	if t1000 != 250 {
    15  		t.Fatal(t1000)
    16  	}
    17  
    18  	t1000 = milliCelsius(0, 0b10000000)
    19  	if t1000 != 500 {
    20  		t.Fatal(t1000)
    21  	}
    22  
    23  	t1000 = milliCelsius(0, 0b11000000)
    24  	if t1000 != 750 {
    25  		t.Fatal(t1000)
    26  	}
    27  
    28  	t1000 = milliCelsius(1, 0b00000000)
    29  	if t1000 != 1000 {
    30  		t.Fatal(t1000)
    31  	}
    32  
    33  	t1000 = milliCelsius(2, 0b00000000)
    34  	if t1000 != 2000 {
    35  		t.Fatal(t1000)
    36  	}
    37  
    38  	// highest temperature is 127.750C
    39  	t1000 = milliCelsius(0x7f, 0b11000000)
    40  	if t1000 != 127750 {
    41  		t.Fatal(t1000)
    42  	}
    43  }
    44  
    45  func TestNegativeMilliCelsius(t *testing.T) {
    46  	t1000 := milliCelsius(0xff, 0b11000000)
    47  	if t1000 != -250 {
    48  		t.Fatal(t1000)
    49  	}
    50  
    51  	t1000 = milliCelsius(0xff, 0b10000000)
    52  	if t1000 != -500 {
    53  		t.Fatal(t1000)
    54  	}
    55  
    56  	t1000 = milliCelsius(0xff, 0b01000000)
    57  	if t1000 != -750 {
    58  		t.Fatal(t1000)
    59  	}
    60  
    61  	t1000 = milliCelsius(0xff, 0b00000000)
    62  	if t1000 != -1000 {
    63  		t.Fatal(t1000)
    64  	}
    65  
    66  	t1000 = milliCelsius(0xfe, 0b00000000)
    67  	if t1000 != -2000 {
    68  		t.Fatal(t1000)
    69  	}
    70  
    71  	// lowest temperature is -128.000C
    72  	t1000 = milliCelsius(0x80, 0b00000000)
    73  	if t1000 != -128000 {
    74  		t.Fatal(t1000)
    75  	}
    76  }