Skip to content

Commit

Permalink
#413 Add tests for FontMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yannsartori authored and prmr committed Feb 16, 2021
1 parent cbd44fc commit 1d8d45c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/ca/mcgill/cs/jetuml/views/TestFontMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ca.mcgill.cs.jetuml.views;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.util.stream.Stream;

import static ca.mcgill.cs.jetuml.views.StringViewer.FONT;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import ca.mcgill.cs.jetuml.geom.Dimension;

public class TestFontMetrics {

private static final FontMetrics aMetrics = new FontMetrics(FONT);
// Ensures there is no caching of sorts when reusing the same Text object
@ParameterizedTest
@MethodSource("stringPairParameters")
public void testStateNotPreserved(String firstString, String secondString)
{

assertNotEquals(aMetrics.getDimension(firstString), aMetrics.getDimension(secondString));
}

private static Stream<Arguments> stringPairParameters() {
return Stream.of(
Arguments.of("X", "XX"),
Arguments.of("XX", "XXX"),
Arguments.of("XXX", "XXXX"),
Arguments.of("XXXX", "XXXXX"),
Arguments.of("XXXXX", "XXXXXX")
);
}

@Test
public void testGetDimensions()
{
assertEquals(new Dimension(0, 11), aMetrics.getDimension(""));
assertEquals(new Dimension(92, 11), aMetrics.getDimension("Single-Line-String"));
assertEquals(new Dimension(29, 39), aMetrics.getDimension("Multi\nLine\nString"));
}

@Test
public void testGetLogicalHeight()
{
assertEquals(14, aMetrics.getLogicalHeight(""));
assertEquals(14, aMetrics.getLogicalHeight("Single-Line-String"));
assertEquals(42, aMetrics.getLogicalHeight("Multi\nLine\nString"));
}
}

0 comments on commit 1d8d45c

Please sign in to comment.