github.com/richardwilkes/toolbox@v1.121.0/xmath/fixed/f64/fraction_test.go (about) 1 // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved. 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, version 2.0. If a copy of the MPL was not distributed with 5 // this file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 // 7 // This Source Code Form is "Incompatible With Secondary Licenses", as 8 // defined by the Mozilla Public License, version 2.0. 9 10 package f64_test 11 12 import ( 13 "testing" 14 15 "github.com/richardwilkes/toolbox/check" 16 "github.com/richardwilkes/toolbox/xmath/fixed" 17 "github.com/richardwilkes/toolbox/xmath/fixed/f64" 18 ) 19 20 func TestFraction(t *testing.T) { 21 check.Equal(t, f64.FromStringForced[fixed.D4]("0.3333"), f64.NewFraction[fixed.D4]("1/3").Value()) 22 check.Equal(t, f64.FromStringForced[fixed.D4]("0.3333"), f64.NewFraction[fixed.D4]("1 / 3").Value()) 23 check.Equal(t, f64.FromStringForced[fixed.D4]("0.3333"), f64.NewFraction[fixed.D4]("-1/-3").Value()) 24 check.Equal(t, f64.From[fixed.D4, int](0), f64.NewFraction[fixed.D4]("5/0").Value()) 25 check.Equal(t, f64.From[fixed.D4, int](5), f64.NewFraction[fixed.D4]("5/1").Value()) 26 check.Equal(t, f64.From[fixed.D4, int](-5), f64.NewFraction[fixed.D4]("-5/1").Value()) 27 check.Equal(t, f64.From[fixed.D4, int](-5), f64.NewFraction[fixed.D4]("5/-1").Value()) 28 }