|
13 | 13 | public class CustomLineHeightSpanTest { |
14 | 14 |
|
15 | 15 | @Test |
16 | | - public void shouldIncreaseAllMetricsProportionally() { |
| 16 | + public void evenLineHeightShouldIncreaseAllMetricsProportionally() { |
17 | 17 | CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(22); |
18 | 18 | Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); |
19 | 19 | fm.top = -10; |
20 | 20 | fm.ascent = -5; |
21 | 21 | fm.descent = 5; |
22 | 22 | fm.bottom = 10; |
23 | 23 | customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); |
| 24 | + // Since line height is even it should be equally added to top and bottom. |
24 | 25 | assertThat(fm.top).isEqualTo(-11); |
25 | | - assertThat(fm.ascent).isEqualTo(-6); |
26 | | - assertThat(fm.descent).isEqualTo(6); |
| 26 | + assertThat(fm.ascent).isEqualTo(-11); |
| 27 | + assertThat(fm.descent).isEqualTo(11); |
27 | 28 | assertThat(fm.bottom).isEqualTo(11); |
| 29 | + assertThat(fm.bottom - fm.top).isEqualTo(22); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void oddLineHeightShouldAlsoWork() { |
| 34 | + CustomLineHeightSpan customLineHeightSpan = new CustomLineHeightSpan(23); |
| 35 | + Paint.FontMetricsInt fm = new Paint.FontMetricsInt(); |
| 36 | + fm.top = -10; |
| 37 | + fm.ascent = -5; |
| 38 | + fm.descent = 5; |
| 39 | + fm.bottom = 10; |
| 40 | + customLineHeightSpan.chooseHeight("Hi", 0, 2, 0, 0, fm); |
| 41 | + // Only test that the sum is correct so the implementation |
| 42 | + // is free to add the odd value either on top or bottom. |
| 43 | + assertThat(fm.descent - fm.ascent).isEqualTo(23); |
| 44 | + assertThat(fm.bottom - fm.top).isEqualTo(23); |
28 | 45 | } |
29 | 46 |
|
30 | 47 | @Test |
|
0 commit comments