Testing code that uses primitive types can be accomplished by writing unit tests that cover the various operations and behaviors associated with those types. Primitive types in Java—such as int, double, boolean, and char—can be easily tested to verify their correctness and expected behavior. Below is an example of how to test a simple method that uses primitive types.
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class PrimitiveTypeTest {
public int add(int a, int b) {
return a + b;
}
public boolean isPositive(int number) {
return number > 0;
}
@Test
public void testAdd() {
assertEquals(5, add(2, 3));
assertEquals(0, add(0, 0));
assertEquals(-1, add(-3, 2));
}
@Test
public void testIsPositive() {
assertTrue(isPositive(5));
assertFalse(isPositive(0));
assertFalse(isPositive(-3));
}
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?