//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.AttributeSystem.Tests;
///
/// Tests for the .
///
[TestFixture]
public class AttributeRelationshipElementTests
{
///
/// Tests if a relationship between two elements with the is handled correctly.
/// Both element values should be summed up, and according to the the inputOperand should be added on top.
///
[Test]
public void InputOperatorAdd()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.Add);
Assert.That(relationshipElement.Value, Is.EqualTo(element1Value + element2Value + inputOperand));
}
///
/// Tests if a relationship between two elements with the is handled correctly.
/// Both element values should be summed up, and according to the the sum should be multiplied with the inputOperand.
///
[Test]
public void InputOperatorMultiply()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.Multiply);
Assert.That(relationshipElement.Value, Is.EqualTo((element1Value + element2Value) * inputOperand));
}
///
/// Tests if a relationship between two elements with the is handled correctly.
/// Both element values should be summed up, and according to the the sum should be raised by the power of inputOperand.
///
[Test]
public void InputOperatorPower()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.Exponentiate);
Assert.That(relationshipElement.Value, Is.EqualTo(Math.Pow(element1Value + element2Value, inputOperand)));
}
///
/// Tests if a relationship between two elements with the is handled correctly.
/// Both element values should be summed up, and according to the the input operand should be raised by the power of the sum.
///
[Test]
public void InputOperatorPowerByAttribute()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.ExponentiateByAttribute);
Assert.That(relationshipElement.Value, Is.EqualTo(Math.Pow(inputOperand, element1Value + element2Value)));
}
///
/// Tests if the is updated correctly when one of the elements value changed.
///
[Test]
public void ValueChangesWhenElementChanges()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.Add);
Assert.That(relationshipElement.Value, Is.EqualTo(element1Value + element2Value + inputOperand));
const int element1NewValue = 2;
element1.Value = element1NewValue;
Assert.That(relationshipElement.Value, Is.EqualTo(element1NewValue + element2Value + inputOperand));
}
///
/// Tests if the is called when one of the elements value changed.
///
[Test]
public void ValueChangedEventWhenElementChanges()
{
const int element1Value = 1;
const int element2Value = 2;
const int inputOperand = 10;
var element1 = new SimpleElement { Value = element1Value };
var element2 = new SimpleElement { Value = element2Value };
var operandElement = new ConstantElement(inputOperand);
var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, operandElement, InputOperator.Add);
var eventCalled = false;
relationshipElement.ValueChanged += (sender, e) => eventCalled = true;
element1.Value = 2;
Assert.That(eventCalled, Is.True);
}
}