committed by
GitHub
23 changed files with 668 additions and 164 deletions
@ -0,0 +1,28 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
namespace Avalonia |
|||
{ |
|||
/// <summary>
|
|||
/// Represents boxed value of type <typeparamref name="T"/>.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of stored value.</typeparam>
|
|||
internal readonly struct BoxedValue<T> |
|||
{ |
|||
public BoxedValue(T value) |
|||
{ |
|||
Boxed = value; |
|||
Typed = value; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Boxed value.
|
|||
/// </summary>
|
|||
public object Boxed { get; } |
|||
|
|||
/// <summary>
|
|||
/// Typed value.
|
|||
/// </summary>
|
|||
public T Typed { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Data; |
|||
using Avalonia.Data.Converters; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Markup.Xaml.UnitTests.Converters |
|||
{ |
|||
public class MultiValueConverterTests : XamlTestBase |
|||
{ |
|||
[Fact] |
|||
public void MultiValueConverter_Special_Values_Work() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<Window xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|||
xmlns:c='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Converters;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|||
<TextBlock Name='textBlock'> |
|||
<TextBlock.Text> |
|||
<MultiBinding Converter='{x:Static c:TestMultiValueConverter.Instance}' FallbackValue='bar'> |
|||
<Binding Path='Item1' /> |
|||
<Binding Path='Item2' /> |
|||
</MultiBinding> |
|||
</TextBlock.Text> |
|||
</TextBlock> |
|||
</Window>";
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var window = (Window)loader.Load(xaml); |
|||
var textBlock = window.FindControl<TextBlock>("textBlock"); |
|||
|
|||
window.ApplyTemplate(); |
|||
|
|||
window.DataContext = Tuple.Create(2, 2); |
|||
Assert.Equal("foo", textBlock.Text); |
|||
|
|||
window.DataContext = Tuple.Create(-3, 3); |
|||
Assert.Equal("foo", textBlock.Text); |
|||
|
|||
window.DataContext = Tuple.Create(0, 2); |
|||
Assert.Equal("bar", textBlock.Text); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class TestMultiValueConverter : IMultiValueConverter |
|||
{ |
|||
public static readonly TestMultiValueConverter Instance = new TestMultiValueConverter(); |
|||
|
|||
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
if (values[0] is int i && values[1] is int j) |
|||
{ |
|||
var p = i * j; |
|||
|
|||
if (p > 0) |
|||
{ |
|||
return "foo"; |
|||
} |
|||
|
|||
if (p == 0) |
|||
{ |
|||
return AvaloniaProperty.UnsetValue; |
|||
} |
|||
|
|||
return BindingOperations.DoNothing; |
|||
} |
|||
|
|||
return "(default)"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,112 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Xunit; |
|||
using Avalonia; |
|||
using System; |
|||
|
|||
namespace Avalonia.Visuals.UnitTests |
|||
{ |
|||
public class VectorTests |
|||
{ |
|||
[Fact] |
|||
public void Length_Should_Return_Correct_Length_Of_Vector() |
|||
{ |
|||
var vector = new Vector(2, 4); |
|||
var length = Math.Sqrt(2 * 2 + 4 * 4); |
|||
|
|||
Assert.Equal(length, vector.Length); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Length_Squared_Should_Return_Correct_Length_Of_Vector() |
|||
{ |
|||
var vectorA = new Vector(2, 4); |
|||
var squaredLengthA = 2 * 2 + 4 * 4; |
|||
|
|||
Assert.Equal(squaredLengthA, vectorA.SquaredLength); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Normalize_Should_Return_Normalized_Vector() |
|||
{ |
|||
// the length of a normalized vector must be 1
|
|||
|
|||
var vectorA = new Vector(13, 84); |
|||
var vectorB = new Vector(-34, 345); |
|||
var vectorC = new Vector(-34, -84); |
|||
|
|||
Assert.Equal(1.0, vectorA.Normalize().Length); |
|||
Assert.Equal(1.0, vectorB.Normalize().Length); |
|||
Assert.Equal(1.0, vectorC.Normalize().Length); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Negate_Should_Return_Negated_Vector() |
|||
{ |
|||
var vector = new Vector(2, 4); |
|||
var negated = new Vector(-2, -4); |
|||
|
|||
Assert.Equal(negated, vector.Negate()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Dot_Should_Return_Correct_Value() |
|||
{ |
|||
var a = new Vector(-6, 8.0); |
|||
var b = new Vector(5, 12.0); |
|||
|
|||
Assert.Equal(66.0, Vector.Dot(a, b)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Cross_Should_Return_Correct_Value() |
|||
{ |
|||
var a = new Vector(-6, 8.0); |
|||
var b = new Vector(5, 12.0); |
|||
|
|||
Assert.Equal(-112.0, Vector.Cross(a, b)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Divied_By_Vector_Should_Return_Correct_Value() |
|||
{ |
|||
var a = new Vector(10, 2); |
|||
var b = new Vector(5, 2); |
|||
|
|||
var expected = new Vector(2, 1); |
|||
|
|||
Assert.Equal(expected, Vector.Divide(a, b)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Divied_Should_Return_Correct_Value() |
|||
{ |
|||
var vector = new Vector(10, 2); |
|||
var expected = new Vector(5, 1); |
|||
|
|||
Assert.Equal(expected, Vector.Divide(vector, 2)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Multiply_By_Vector_Should_Return_Correct_Value() |
|||
{ |
|||
var a = new Vector(10, 2); |
|||
var b = new Vector(2, 2); |
|||
|
|||
var expected = new Vector(20, 4); |
|||
|
|||
Assert.Equal(expected, Vector.Multiply(a, b)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Multiply_Should_Return_Correct_Value() |
|||
{ |
|||
var vector = new Vector(10, 2); |
|||
|
|||
var expected = new Vector(20, 4); |
|||
|
|||
Assert.Equal(expected, Vector.Multiply(vector, 2)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue