Skip to content

Commit

Permalink
Add a unit test for DiffusionEffect.
Browse files Browse the repository at this point in the history
  • Loading branch information
sesse committed Oct 14, 2012
1 parent 57acdb1 commit 4b8eee7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -23,6 +23,7 @@ TESTS += saturation_effect_test
TESTS += deconvolution_sharpen_effect_test
TESTS += blur_effect_test
TESTS += unsharp_mask_effect_test
TESTS += diffusion_effect_test

# Core.
LIB_OBJS=util.o widgets.o effect.o effect_chain.o
Expand Down Expand Up @@ -79,6 +80,8 @@ blur_effect_test: blur_effect_test.o $(TEST_OBJS) libmovit.a
$(CXX) -o $@ $^ $(LDFLAGS)
unsharp_mask_effect_test: unsharp_mask_effect_test.o $(TEST_OBJS) libmovit.a
$(CXX) -o $@ $^ $(LDFLAGS)
diffusion_effect_test: diffusion_effect_test.o $(TEST_OBJS) libmovit.a
$(CXX) -o $@ $^ $(LDFLAGS)

OBJS=$(DEMO_OBJS) $(LIB_OBJS) $(TEST_OBJS) $(TESTS:=.o)

Expand Down
60 changes: 60 additions & 0 deletions diffusion_effect_test.cpp
@@ -0,0 +1,60 @@
// Unit tests for DiffusionEffect.

#include "test_util.h"
#include "gtest/gtest.h"
#include "diffusion_effect.h"

TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
const int size = 4;

float data[size * size] = {
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 1.0, 0.0,
0.0, 0.5, 1.0, 0.5,
0.0, 0.0, 0.0, 0.0,
};
float out_data[size * size];

EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);

expect_equal(data, out_data, size, size);
}

TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
const int size = 9;

float data[size * size] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
};
float expected_data[size * size] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
};
float out_data[size * size];

EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);

expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
}

0 comments on commit 4b8eee7

Please sign in to comment.