// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package org.wpilib.units; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertSame; import static org.wpilib.units.Units.Degrees; import static org.wpilib.units.Units.Foot; import static org.wpilib.units.Units.Inches; import org.junit.jupiter.api.Test; class PerUnitTest { @Test void ofNative() { ExampleUnit part = new ExampleUnit(1); var unit = PerUnit.combine(part, part); assertEquals(10, unit.ofNative(10).in(unit)); // Does not compile: // unit.of(10).in(unit); // // error: incompatible types: PerUnit cannot be converted to CAP#1 // unit.of(10).in(unit); // ^ // where CAP#1 is a fresh type-variable: // CAP#1 extends PerUnit // from capture of ? extends PerUnit // This is because `of` returns a `Measure>`, // and a `Per` object isn't a subtype of that anonymous wildcard bound } @Test void multSameDenom() { var unit = Degrees.per(Foot); var result = unit.mult(Foot); // Multiplying by the same unit as the divisor should return the dividend unit assertSame(Degrees, result); } @Test void multOtherDenom() { var unit = Degrees.per(Foot); // (Degrees / Foot) x Inches, or 1/12 of a degree var result = unit.mult(Inches); assertInstanceOf(AngleUnit.class, result); assertEquals(1 / 12.0, result.of(1).in(Degrees), 1e-9); assertEquals("Degree per Foot Inch", result.name()); assertEquals("°/ft-in", result.symbol()); } }