Improved previous tests readability

This commit is contained in:
Michaël Lemaire 2013-06-16 15:30:56 +02:00
parent db51b3af81
commit 2d866442e7

View file

@ -132,123 +132,65 @@ START_TEST(test_terrain_painting_brush_smooth)
END_TEST
static void _checkBrushResult(TerrainDefinition* terrain, TerrainBrush* brush, double center, double midhard, double hard, double midsoft, double soft, double exter)
{
UNUSED(brush);
ck_assert_double_eq(terrainGetGridHeight(terrain, -5, 0, 1), exter);
ck_assert_double_eq(terrainGetGridHeight(terrain, -4, 0, 1), soft);
ck_assert_double_eq(terrainGetGridHeight(terrain, -3, 0, 1), midsoft);
ck_assert_double_eq(terrainGetGridHeight(terrain, -2, 0, 1), hard);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), midhard);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), center);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), midhard);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), hard);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), midsoft);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), soft);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), exter);
}
START_TEST(test_terrain_painting_brush_flatten)
{
/* Set up */
TerrainDefinition* terrain = _setUpDefinition();
TerrainBrush brush;
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
terrain->height = 1.0;
terrain->scaling = 1.0;
noiseForceValue(terrain->_height_noise, 0.0);
/* Test flattening center at 0.5 */
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
terrainBrushFlatten(terrain->height_map, &brush, 0.5, 1.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.5);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.5);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.5);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.5);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.25);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
_checkBrushResult(terrain, &brush, 0.5, 0.5, 0.5, 0.25, 0.0, 0.0);
/* Test brush strength */
terrainClearPainting(terrain->height_map);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
terrainBrushFlatten(terrain->height_map, &brush, 0.5, 0.01);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.005);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.005);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.005);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.005);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0025);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
_checkBrushResult(terrain, &brush, 0.005, 0.005, 0.005, 0.0025, 0.0, 0.0);
/* Test cumulative effect */
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
terrainBrushFlatten(terrain->height_map, &brush, 0.5, 0.01);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.00995);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.00995);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.00995);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.00995);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0049875);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
_checkBrushResult(terrain, &brush, 0.00995, 0.00995, 0.00995, 0.0049875, 0.0, 0.0);
/* Test with height modifier */
terrain->height = 10.0;
terrainClearPainting(terrain->height_map);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
terrainBrushFlatten(terrain->height_map, &brush, 0.5, 1.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.025);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
_checkBrushResult(terrain, &brush, 0.05, 0.05, 0.05, 0.025, 0.0, 0.0);
/* Test with scaling modifier */
terrain->height = 10.0;
terrain->scaling = 2.0;
terrainClearPainting(terrain->height_map);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
brush.relative_x = 0.0;
brush.relative_z = 0.0;
brush.hard_radius = 2.0;
brush.smoothed_size = 2.0;
brush.total_radius = 4.0;
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
terrainBrushFlatten(terrain->height_map, &brush, 0.5, 1.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, -1, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 0, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 1, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 2, 0, 1), 0.05);
ck_assert_double_eq(terrainGetGridHeight(terrain, 3, 0, 1), 0.025);
ck_assert_double_eq(terrainGetGridHeight(terrain, 4, 0, 1), 0.0);
ck_assert_double_eq(terrainGetGridHeight(terrain, 5, 0, 1), 0.0);
_checkBrushResult(terrain, &brush, 0.05, 0.05, 0.05, 0.025, 0.0, 0.0);
/* Tear down */
_tearDownDefinition(terrain);