1
2
3
4
5
6
7
8
9
10
11
12
13
14 package fuzzy.df;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.fail;
18
19 import java.text.DecimalFormat;
20
21 import org.apache.commons.functor.generator.range.DoubleRange;
22 import org.junit.Test;
23
24 import fuzzy.mf.MembershipFunction;
25 import fuzzy.mf.SigmoidalMembershipFunction;
26
27
28
29
30
31
32
33
34 public class TestCentroidDefuzzificationFunction extends BaseDefuzzificationFunctionTest<CentroidDefuzzificationFunction<Double>>{
35
36 @Override
37 protected CentroidDefuzzificationFunction<Double> makeDefuzzificationFunction() {
38 final CentroidDefuzzificationFunction<Double> df = new CentroidDefuzzificationFunction<Double>();
39 return df;
40 }
41
42 @Test
43 public void testDefuzzification() {
44 CentroidDefuzzificationFunction<Double> df = makeDefuzzificationFunction();
45 DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1);
46 MembershipFunction<Double> mf = new SigmoidalMembershipFunction(-10.0, 10.0);
47 Double d = df.apply(range, mf);
48 assertEquals(Integer.valueOf(0).toString(), new DecimalFormat("#.#").format(Math.abs(d)));
49 }
50
51 @Test(expected=IllegalArgumentException.class)
52 public void testDefuzzificationEmptySet() {
53 CentroidDefuzzificationFunction<Double> df = makeDefuzzificationFunction();
54 DoubleRange range = new DoubleRange(0.0, 0.0);
55 MembershipFunction<Double> mf = new SigmoidalMembershipFunction(-10.0, 10.0);
56 df.apply(range, mf);
57 fail("Not supposed to get here");
58 }
59
60 }