gioui.org@v0.6.1-0.20240506124620-7a9ce51988ce/unit/unit_test.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package unit_test 4 5 import ( 6 "testing" 7 8 "gioui.org/unit" 9 ) 10 11 func TestMetric_DpToSp(t *testing.T) { 12 m := unit.Metric{ 13 PxPerDp: 2, 14 PxPerSp: 3, 15 } 16 17 { 18 exp := m.Dp(5) 19 got := m.Sp(m.DpToSp(5)) 20 if got != exp { 21 t.Errorf("DpToSp conversion mismatch %v != %v", exp, got) 22 } 23 } 24 25 { 26 exp := m.Sp(5) 27 got := m.Dp(m.SpToDp(5)) 28 if got != exp { 29 t.Errorf("SpToDp conversion mismatch %v != %v", exp, got) 30 } 31 } 32 33 { 34 exp := unit.Dp(5) 35 got := m.PxToDp(m.Dp(5)) 36 if got != exp { 37 t.Errorf("PxToDp conversion mismatch %v != %v", exp, got) 38 } 39 } 40 41 { 42 exp := unit.Sp(5) 43 got := m.PxToSp(m.Sp(5)) 44 if got != exp { 45 t.Errorf("PxToSp conversion mismatch %v != %v", exp, got) 46 } 47 } 48 }