Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/test/processing/core/PFontTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package processing.core;

import java.awt.Font; //Javas built in font class
import org.junit.Test; //Using Junit4 test implementation
import static org.junit.Assert.assertEquals; //To compare expected vs actual values

public class PFontTest {

@Test
public void constructor_setsSizeCorrectly() {
Font awtFont = new Font("Dialog", Font.PLAIN, 16); //Truth, what PFont size should be
PFont font = new PFont(awtFont, true, null); //call to constructor w specific values
assertEquals(16, font.getSize()); //actual test, expects 16 compares against actual value
}
}
45 changes: 45 additions & 0 deletions core/test/processing/core/PFontTestHelp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

What I think we need to test for broken up into chunks... trying to keep it organized

Chunk A — Construction and initialization

NEED TO TEST IF...

the object starts in the correct mode
important fields are initialized correctly
lookup structures are prepared correctly
lazy vs non-lazy behavior is set based on constructor input
charset input is handled safely and predictably

SOME TEST EXAMPLES...

charset == null should put the font in lazy mode
ascii array should start filled with -1
provided charset should be sorted internally, without changing the caller’s original array
only displayable characters should become glyphs
ascent/descent get initialized one way or another

Chunk B — Serialization and deserialization

NEED TO TEST IF...

font data can be saved and loaded without corruption
important metadata survives the round trip
glyph structure and bitmap data remain consistent
bad/invalid serialized data fails in the expected way

SOME TEST EXAMPLES...

save a font, reload it, compare glyphCount, size, name, psname, smooth
glyph widths/heights still match after reload
invalid stream data should throw instead of silently building a broken font



Chunk C — Glyph insertion and ordering --will add more if we get through chunks A & B
Chunk D — Glyph lookup and lazy loading
Chunk E — Metrics and width calculations
Chunk F — Native font integration
Chunk G — Shape generation
Chunk H — Static charset and font listing
Chunk I — Glyph inner-class bitmap/header behavior
135 changes: 135 additions & 0 deletions core/test/processing/data/FloatListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package processing.data;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

public class FloatListTest {
@Test
public void testConstructorDefault(){
FloatList testList = new FloatList();

assertEquals(0, testList.size());
assertEquals(10, testList.data.length);
}

@Test
public void testConstructorLength(){
FloatList testList = new FloatList(15);

assertEquals(0, testList.size());
assertEquals(15, testList.data.length);
}

@Test
public void testConstructorArray(){
FloatList testList = new FloatList(new float[] {1.1F, 2.2F, 3.3F});

assertEquals(3, testList.size());
assertEquals(3, testList.data.length);

assertEquals(1.1F, testList.get(0), 0.0F);
assertEquals(3.3F, testList.get(2), 0.0F);
}

@Test
public void testConstructorIterableObject(){
List<Object> src = new ArrayList<>(Arrays.asList("String", 9, 10.4F, 3.7, null));
FloatList testList = new FloatList(src);
assertEquals(5, testList.size());

float[] expected = {Float.NaN, 9.0F, 10.4F, 3.7F, Float.NaN};
assertEquals(expected[0], testList.get(0), 0.0F);
assertEquals(expected[1], testList.get(1), 0.0F);
assertEquals(expected[2], testList.get(2), 0.0F);
assertEquals(expected[3], testList.get(3), 0.0F);
}

@Test
public void testConstructorObject(){
String typeStr = "String";
int typeInt = 21;
float typeFlt = 4.5F;
Object typeObj = new Object();

FloatList testList = new FloatList(typeStr, typeInt, typeFlt, typeObj);

float[] expected = {Float.NaN, 21.0F, 4.5F, Float.NaN};
assertEquals(expected[0], testList.get(0), 0.0F);
assertEquals(expected[1], testList.get(1), 0.0F);
assertEquals(expected[2], testList.get(2), 0.0F);
assertEquals(expected[3], testList.get(3), 0.0F);
}

@Test
public void testSize(){
FloatList testList = new FloatList(new float[]{1.1F, 2.2F, 3.3F});

assertEquals(3, testList.size());
}

@Test
public void testResize(){
FloatList testList = new FloatList(new float[]{3.3F, 4.4F, 5.5F});

assertEquals(3, testList.size());

testList.resize(10);
assertEquals(10, testList.size());
assertEquals(10, testList.data.length);
}

@Test
public void testClear(){
FloatList testList = new FloatList(new float[]{45.8F, 5.6F, 9.8F});

assertEquals(3, testList.size());
testList.clear();
assertEquals(0, testList.size());
}

@Test
public void testGet(){
FloatList testList = new FloatList(new float[]{4.5F, 7.8F});

assertEquals(4.5F, testList.get(0), 0.0F);
assertEquals(7.8F, testList.get(1), 0.0F);
}

@Test
public void testSet(){
FloatList testList = new FloatList();

testList.set(0, 18.0F);
assertEquals(1, testList.size());
assertEquals(18.0F, testList.get(0), 0.0F);

testList.set(500, 4.9F);
assertEquals(501, testList.size());
assertEquals(4.9F, testList.get(500), 0.0F);
}

@Test
public void testPush(){
FloatList testList = new FloatList();
testList.push(34.0F);

assertEquals(1, testList.size());
assertEquals(34.0F, testList.get(0), 0.0F);
}

@Test
public void testPop(){
FloatList testList = new FloatList(new float[]{6.0F, 7.0F});

assertEquals(7.0F, testList.pop(), 0.0F);
assertEquals(1, testList.size());

assertEquals(6.0F, testList.pop(), 0.0F);
assertEquals(0, testList.size());
}
}