public void NullTarget() { var binding = new MethodBindingExtension(new NullExtension(), "SomeMethod"); TestHelper.RunMethodBinding(null, binding); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] First method binding argument is required and cannot resolve to null - method name or method target expected.", }); }
public void NullDataContext() { var binding = new MethodBindingExtension("SomeMethod"); TestHelper.RunMethodBinding(null, binding); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] Null data context for method 'SomeMethod' on element 'TestElement' (type: 'System.Windows.FrameworkElement').", }); }
public void NoParameters() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.NoParameters)); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(true); TraceMessages.ShouldBeEmpty(); }
public void IntParameterAsXamlString() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.IntParam), "5"); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(true); vm.ParamType.ShouldBe(typeof(int)); TraceMessages.ShouldBeEmpty(); }
public void OverloadedNullableIntDoubleAsNull() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.OverloadedNullableIntDouble), null); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(true); vm.ParamType.ShouldBe(typeof(int?)); TraceMessages.ShouldBeEmpty(); }
public void OverloadedIntStringAsInt() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.OverloadedIntString), 5); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(true); vm.ParamType.ShouldBe(typeof(int)); TraceMessages.ShouldBeEmpty(); }
public void NullableIntParameterAsNullExtension() { var vm = new ViewModel(); var binding = new MethodBindingExtension(nameof(ViewModel.NullableIntParam), new NullExtension()); TestHelper.RunMethodBinding(vm, binding); vm.Executed.ShouldBe(true); vm.ParamType.ShouldBe(typeof(int?)); TraceMessages.ShouldBeEmpty(); }
public void OverloadedNullableIntDoubleAsString() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.OverloadedNullableIntDouble), "5"); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(false); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] Could not find method 'OverloadedNullableIntDouble' (target type 'Singulink.WPF.Data.Tests.ViewModel') that accepts the provided arguments ('System.String').", }); }
public void IntParameterAsNullExtension() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, nameof(ViewModel.IntParam), new NullExtension()); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(false); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] Method 'IntParam' (target type 'Singulink.WPF.Data.Tests.ViewModel') parameter 1 (name: 'x', type: 'System.Int32') is not assignable to null.", }); }
public void NullMethodName() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, new NullExtension()); TestHelper.RunMethodBinding(null, binding); binding = new MethodBindingExtension(vm, null); TestHelper.RunMethodBinding(null, binding); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] Method target type resolved to 'Singulink.WPF.Data.Tests.ViewModel', method name resolved to null.", "testhost Warning: 0 : [MethodBindingExtension] Method target type resolved to 'Singulink.WPF.Data.Tests.ViewModel', method name resolved to null.", }); }
public void MissingMethod() { var vm = new ViewModel(); var binding = new MethodBindingExtension(vm, "NonExistent"); TestHelper.RunMethodBinding(null, binding); binding = new MethodBindingExtension(vm, "NonExistent", null); TestHelper.RunMethodBinding(null, binding); vm.Executed.ShouldBe(false); TraceMessages.ShouldBe(new[] { "testhost Warning: 0 : [MethodBindingExtension] Could not find parameterless method 'NonExistent' (target type 'Singulink.WPF.Data.Tests.ViewModel').", "testhost Warning: 0 : [MethodBindingExtension] Could not find method 'NonExistent' (target type 'Singulink.WPF.Data.Tests.ViewModel') that accepts the provided arguments (null).", }); }
public int ClosestClassifier() { int [] errorScores = new int[3]; for (int n = 0; n <= 2; n++) { int currentError = 0; for (int h = 0; h < 1023; h++) { currentError = currentError + Math.Abs(learnedHistograms[3][h] - learnedHistograms[n][h]); } errorScores[n] = currentError; TraceMessages.AddMessage($"Comparison with case {n} yields error score of {currentError}"); } int minIndex = Array.IndexOf(errorScores, errorScores.Min()); return(minIndex); }
public void ShowHistogram(int classifier) { int[] histogramToShow; if (classifier == -1) { histogramToShow = histogramToClassify; } else { histogramToShow = learnedHistograms[classifier]; } TraceMessages.AddMessage($"Showing classifier for {classifier}"); for (int i = 0; i < histogramToShow.Length; i++) { if (histogramToShow[i] != 0) { TraceMessages.AddMessage($"{i} = {histogramToShow[i]}"); } } }