1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    *     http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an
10   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11   * either express or implied. See the License for the specific language
12   * governing permissions and limitations under the License.
13   */
14  package fuzzy.df;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  import java.text.DecimalFormat;
19  
20  import org.apache.commons.functor.generator.range.DoubleRange;
21  import org.junit.Test;
22  
23  import fuzzy.mf.MembershipFunction;
24  import fuzzy.mf.TrapezoidalMembershipFunction;
25  
26  
27  /**
28   * Tests for Smallest Of Maxima Defuzzification Function.
29   *
30   * @since 0.2
31   * @see SmallestOfMaximaDefuzzificationFunction
32   */
33  public class TestMeanOfMaximaDefuzzificationFunction extends BaseDefuzzificationFunctionTest<MeanOfMaximaDefuzzificationFunction<Double>>{
34  
35  	@Override
36  	protected MeanOfMaximaDefuzzificationFunction<Double> makeDefuzzificationFunction() {
37  		final MeanOfMaximaDefuzzificationFunction<Double> df = new MeanOfMaximaDefuzzificationFunction<Double>();
38  		return df;
39  	}
40  
41  	@Test
42  	public void testDefuzzification() {
43  	    MeanOfMaximaDefuzzificationFunction<Double> df = makeDefuzzificationFunction();
44  		DoubleRange range = new DoubleRange(-10.0, 10.0, 0.1);
45  		MembershipFunction<Double> mf = new TrapezoidalMembershipFunction(-10.0, -8.0, -4.0, 7.0);
46          Double d = df.apply(range, mf);
47  		assertEquals(Integer.valueOf(-6).toString(), new DecimalFormat("#.#").format(d));
48  	}
49  
50  }