Exemple #1
0
func TestDefuzzify(t *testing.T) {
	engine.Fuzzify(testObject)
	engine.Infer()

	defuzzyOperator = "cog"
	engine.Defuzzify()
	if !engine.isComputed {
		t.Error("Return value not computed...")
	}

	output := engine.result
	expected := -25.3125
	if !utilities.CompareEpsilon(output, expected) {
		t.Errorf("Expected: %v, got: %v", expected, output)
	}

	defuzzyOperator = "mm"
	engine.Defuzzify()
	if !engine.isComputed {
		t.Error("Return value not computed...")
	}

	output = engine.result
	expected = -78.75
	if !utilities.CompareEpsilon(output, expected) {
		t.Errorf("Expected: %v, got: %v", expected, output)
	}
}
Exemple #2
0
func TestSinusoidalSetBuilder(t *testing.T) {
	var expected = []float64{
		0, 0, 0, 0, 0.146447, 0.5, 0.853553, 1, 1, 1, 1, 1, 1, 1, 0.853553, 0.5, 0.146447, 0, 0, 0, 0,
	}

	function, err := SinusoidalSetBuilder(minSupport, minCore, maxCore, maxSupport)

	if err != nil {
		t.Error("Error while building the function.")
	}

	for i, value := range values {
		result := function(value)
		if !utilities.CompareEpsilon(result, expected[i]) {
			t.Errorf("Expected: %v, got: %v", expected[i], result)
		}
	}
}
Exemple #3
0
func TestBooleanSetBuilder(t *testing.T) {
	var expected = []float64{
		0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
	}

	function, err := BooleanSetBuilder(minCore, maxCore)

	if err != nil {
		t.Error("Error while building the function.")
	}

	for i, value := range values {
		result := function(value)
		if !utilities.CompareEpsilon(result, expected[i]) {
			t.Errorf("Expected: %v, got: %v", expected[i], result)
		}
	}
}