public void AddChild2 () { var x = new ArrayExtension (new int [0]); x.AddChild (new object ()); x.AddChild (5); x.AddChild ("test"); }
public void AddInconsistent2 () { var x = new ArrayExtension (new int [] {1, 3}); Assert.AreEqual (typeof (int), x.Type, "#1"); x.AddChild (new object ()); Assert.AreEqual (typeof (int), x.Type, "#2"); }
public void AddInconsistent () { var x = new ArrayExtension (typeof (int)); Assert.AreEqual (typeof (int), x.Type, "#1"); // adding inconsistent items is not rejected, while calling ProvideValue() results in an error. x.AddChild (new object ()); Assert.AreEqual (typeof (int), x.Type, "#2"); }
public void ArrayExtensionConstructor() { tlog.Debug(tag, $"ArrayExtensionConstructor START"); ArrayExtension arrayExtension = new ArrayExtension(); Assert.IsNotNull(arrayExtension, "null ArrayExtension"); Assert.IsInstanceOf <ArrayExtension>(arrayExtension, "Should return ArrayExtension instance."); tlog.Debug(tag, $"ArrayExtensionConstructor END"); }
public void FilterArrayByKeyMethod_ArrayWithoutKeyValue_EmptyArray() { int[] array = new int[] { -678, 7, 3, 9, 1, 9, -56 }; int key = 0; int[] expected = new int[] { }; int[] actual = ArrayExtension.FilterArrayByKey(array, key); Assert.AreEqual(string.Join(",", expected), string.Join(",", actual)); }
public void FilterArrayByKeyMethod_OrdinaryArrayKey4_FilteredArray() { int[] array = new int[] { 14, 64, 98, 0, -3, 87, 43, 64, 99, 52, 87 }; int key = 4; int[] expected = new int[] { 14, 64, 43, 64 }; int[] actual = ArrayExtension.FilterArrayByKey(array, key); Assert.AreEqual(string.Join(",", expected), string.Join(",", actual)); }
public void FilterNumbers_WithDigit4_Success() { int[] array = new int[] { 4, 24, 27, 74, 101 }; PredicateDigit4 digit = new PredicateDigit4(); int[] expected = new int[] { 4, 24, 74 }; int[] actual = ArrayExtension.FilterNumbers(array, digit); CollectionAssert.AreEqual(expected, actual); }
public void FilterArrayByKeyMethod_OrdinaryArrayKey7_FilteredArray() { int[] array = new int[] { 7, 1, 2, 3, 4, 5, 6, 7, 68, 69, 70, 15, 17 }; int key = 7; int[] expected = new int[] { 7, 7, 70, 17 }; int[] actual = ArrayExtension.FilterArrayByKey(array, key); Assert.AreEqual(string.Join(",", expected), string.Join(",", actual)); }
public void FilterArrayByKeyMethod_OrdinaryArrayKey3_FilteredArray() { int[] array = new int[] { 3, 315, 9, 0, 45, 0, 32, -98, -535 }; int key = 3; int[] expected = new int[] { 3, 315, 32, -535 }; int[] actual = ArrayExtension.FilterArrayByKey(array, key); Assert.AreEqual(string.Join(",", expected), string.Join(",", actual)); }
public void ProvideValueInconsistent2() { Assert.Throws(typeof(InvalidOperationException), () => { var x = new ArrayExtension(new int[] { 1, 3 }); x.AddChild(new object()); x.AddChild(null); // allowed Assert.AreEqual(4, x.Items.Count); x.ProvideValue(null); }); }
public void SortTests(int[] array) { int[] arraySystem = new int[array.Length]; Array.Copy(array, arraySystem, array.Length); Array.Sort(arraySystem); ArrayExtension.Sort(array); IStructuralEquatable iArray = arraySystem; Assert.IsTrue(iArray.Equals(array, StructuralComparisons.StructuralEqualityComparer)); }
public void FilterNumbers_WithDigit3_Success() { int[] array = new int[] { 3, 2, 77, 37, 701 }; PredicateDigit3 digit = new PredicateDigit3(); int[] expected = new int[] { 3, 37 }; int[] actual = ArrayExtension.FilterNumbers(array, digit); CollectionAssert.AreEqual(expected, actual); }
public void FilterNumbers_WithNegativeDigit6_Success() { int[] array = new int[] { 6, 2, -76, -6, -701 }; PredicateDigit6 digit = new PredicateDigit6(); int[] expected = new int[] { 6, -76, -6 }; int[] actual = ArrayExtension.FilterNumbers(array, digit); CollectionAssert.AreEqual(expected, actual); }
public void FilterNumbers_WithDigit5_Success() { int[] array = new int[] { 51, 2, 5, 7, 751 }; PredicateDigit5 digit = new PredicateDigit5(); int[] expected = new int[] { 51, 5, 751 }; int[] actual = ArrayExtension.FilterNumbers(array, digit); CollectionAssert.AreEqual(expected, actual); }
public void SortTheArray_RandomArray_SortedArray() { var expected = GenerateRandomSortedArray(1000000, int.MaxValue); var actual = (int[])expected.Clone(); Shuffle(actual); ArrayExtension.SortTheArray(actual); Assert.AreEqual(expected, actual); }
public void FilterNumbers_WithDigit0_Unsuccess() { int[] array = new int[] { 0, 10, 20, 111, 456 }; PredicateDigit0 digit = new PredicateDigit0(); int[] expected = new int[] { 0, 10, 20, 111, 250 }; int[] actual = ArrayExtension.FilterNumbers(array, digit); CollectionAssert.AreEqual(expected, actual); }
/** Trying to make an ascii art of the pyraminx stickers position... * * U * ____ ____ ____ ____ ____ ____ * \ /\ /\ / /\ \ /\ /\ / * \0 /1 \2 /4 \3 / /0 \ \0 /1 \2 /4 \3 / * \/____\/____\/ /____\ \/____\/____\/ * \ /\ / /\ /\ \ /\ / * face 2 \8 /7 \5 / /8 \1 /2 \ \8 /7 \5 / face 3 * \/____\/ /____\/____\ \/____\/ * \ / /\ /\ /\ \ / * \6 / /6 \7 /5 \4 /3 \ \6 / * \/ /____\/____\/____\ \/ * face 0 * L ____ ____ ____ R * \ /\ /\ / * \0 /1 \2 /4 \3 / * \/____\/____\/ * \ /\ / * \8 /7 \5 / * face 1 \/____\/ * \ / * \6 / * \/ * * B */ public PyraminxState(PyraminxPuzzle p) : base(p) { _puzzle = p; _image = ArrayExtension.New <int>(4, 9); for (var i = 0; i < _image.Length; i++) { for (var j = 0; j < _image[0].Length; j++) { _image[i][j] = i; } } }
public void MergeSortMethod_LargeArray_SortAscending() { // Arrange int[] array = RandomArrayGenerating.GenerateArray(1000); // Act int[] actual = ArrayExtension.MergeSort(array); bool result = SortedArrayChecker.CheckSortedArray(array); // Assert Assert.IsTrue(result); }
public void QuickSortMethod_OrdinaryArrayWithNegativeInt_SortAscending() { // Arrange int[] array = new int[] { -18, 0, int.MaxValue, int.MinValue, 6, -1000 }; // Act int[] actual = ArrayExtension.QuickSort(array); bool result = SortedArrayChecker.CheckSortedArray(array); // Assert Assert.IsTrue(result); }
public MegaminxState(MegaminxPuzzle p) : base(p) { _puzzle = p; _image = ArrayExtension.New <int>(12, 11); for (var i = 0; i < _image.Length; i++) { for (var j = 0; j < _image[0].Length; j++) { _image[i][j] = i; } } _normalizedState = this; }
public void FindMaximumItem_RandomArray_MaxItem() { var array = GenerateRandomSortedArray(100000, int.MaxValue); int expected = array[array.Length - 1]; var shuffleArray = (int[])array.Clone(); Shuffle(shuffleArray); var actual = ArrayExtension.FindMaximumItem(shuffleArray); Assert.AreEqual(expected, actual); }
/// <summary> /// 根据类型获取成员信息集合 /// </summary> /// <param name="type">类型</param> /// <returns>成员信息集合</returns> private static MemberIndex[] getStaticMembers(Type type) { MemberIndex[] members; if (!staticMemberCache.TryGetValue(type, out members)) { MemberIndexGroup group = StaticMemberIndexGroup.Get(type); staticMemberCache[type] = members = ArrayExtension.concat(group.PublicFields.getArray(value => new MemberIndex(value)), group.NonPublicFields.getArray(value => new MemberIndex(value)), group.PublicProperties.getArray(value => new MemberIndex(value)), group.NonPublicProperties.getArray(value => new MemberIndex(value))); } return(members); }
public void ProvideValue() { var x = new ArrayExtension(new int [] { 1, 3 }); x.AddChild(5); Assert.AreEqual(3, x.Items.Count); var ret = x.ProvideValue(null); Assert.IsNotNull(ret, "#1"); var arr = ret as int []; Assert.IsNotNull(arr, "#2"); Assert.AreEqual(3, arr.Length, "#3"); Assert.AreEqual(5, arr [2], "#4"); }
/// <summary> /// Разбор конфигурации из устройства /// </summary> private void SpreadConfig() { byte[] workArray = new byte[2] { ArrayExtension.HIBYTE(Config), ArrayExtension.LOBYTE(Config) }; BitArray workBits = new BitArray(workArray); BitValues = workBits[12]; ParityOdd = workBits[13]; ParityExistence = workBits[14]; StopBitCount = workBits[15]; byte speedbyte = SpeedByteFromBits(workBits[8], workBits[9], workBits[10], workBits[11]); ModbusSpeed = ModbusSpeedDictionary.FirstOrDefault(x => x.Value == speedbyte).Key; }
//探索結果をリセットする public void ResetResult() { ArrayExtension.ForEach(Nodes, (p, n) => { n.Status = NodeStatus.None; n.Cost = int.MaxValue; n.HeuristicCost = int.MaxValue; n.TotalCost = int.MaxValue; n.Turn = 0; n.SuccessProbability = 1.0; n.Parent = null; }); BestWayNodes = null; BestWayPoints = null; }
public CubeState(CubePuzzle cp) : base(cp) { _puzzle = cp; _image = ArrayExtension.New <int>(6, _puzzle.Size, _puzzle.Size); for (var face = 0; face < _image.Length; face++) { for (var j = 0; j < _puzzle.Size; j++) { for (var k = 0; k < _puzzle.Size; k++) { _image[face][j][k] = face; } } } _normalizedState = this; }
private void SetAllPicon2(ushort[] value) { byte[] bytesValue = ArrayExtension.UshortArrayToByteArray(value); this.SetAllPicon2(this.uiVoltageA, bytesValue, 0, 2, Picon2MeterFormatterSelector.SELECTOR_VOLTAGE); this.SetAllPicon2(this.uiVoltageB, bytesValue, 2, 2, Picon2MeterFormatterSelector.SELECTOR_VOLTAGE); this.SetAllPicon2(this.uiVoltageC, bytesValue, 4, 2, Picon2MeterFormatterSelector.SELECTOR_VOLTAGE); this.SetAllPicon2(this.uiCurrentA, bytesValue, 6, 2, Picon2MeterFormatterSelector.SELECTOR_CURRENT); this.SetAllPicon2(this.uiCurrentB, bytesValue, 8, 2, Picon2MeterFormatterSelector.SELECTOR_CURRENT); this.SetAllPicon2(this.uiCurrentC, bytesValue, 10, 2, Picon2MeterFormatterSelector.SELECTOR_CURRENT); this.SetAllPicon2(this.uiPowerA, bytesValue, 12, 2, Picon2MeterFormatterSelector.SELECTOR_POWER); this.SetAllPicon2(this.uiPowerB, bytesValue, 14, 2, Picon2MeterFormatterSelector.SELECTOR_POWER); this.SetAllPicon2(this.uiPowerC, bytesValue, 16, 2, Picon2MeterFormatterSelector.SELECTOR_POWER); this.SetAllPicon2(this.uiEnergyO, bytesValue, 18, 4, Picon2MeterFormatterSelector.SELECTOR_ENERGY); //this.SetAllPicon2(this.uiEnergyM, bytesValue, 26, 4, Picon2MeterFormatterSelector.SELECTOR_ENERGY); //this.SetAllPicon2(this.uiEnergyD, bytesValue, 30, 4, Picon2MeterFormatterSelector.SELECTOR_ENERGY); }
/// <summary> /// Разбор конфигурации из устройства /// </summary> private void SpreadConfig() { //refactor byte[] workArray = new byte[2] { ArrayExtension.HIBYTE(Config), ArrayExtension.LOBYTE(Config) }; BitArray workBits = new BitArray(workArray); Speed = workBits[8]; Protocol = workBits[9]; Filter = workBits[10]; Amplifier = workBits[11]; BitValues = workBits[12]; ParityOdd = workBits[13]; ParityExistence = workBits[14]; StopBitCount = workBits[15]; }
public static void Init() { for (int i = 0; i < 12; i++) { std2rl[rl2std[i]] = i; } Center3 c = new Center3(); for (int i = 0; i < 35 * 35 * 12 * 2; i++) { for (int m = 0; m < 20; m++) { c.Setct(i); c.Move(m); Ctmove[i][m] = (char)c.Getct(); } } ArrayExtension.Fill(Prun, (sbyte)-1); Prun[0] = 0; int depth = 0; int done = 1; while (done != 29400) { for (int i = 0; i < 29400; i++) { if (Prun[i] != depth) { continue; } for (int m = 0; m < 17; m++) { if (Prun[Ctmove[i][m]] == -1) { Prun[Ctmove[i][m]] = (sbyte)(depth + 1); done++; } } } depth++; } }
public void Initialize(Vector2 size) { this.size = size; gridBackgrounds = ArrayExtension.New2DArray <Background>((int)size.x, (int)size.y); piecebackGroundObjectPool.PoolAll(); for (int i = 0; i < size.x; i++) { for (int j = 0; j < size.y; j++) { GameObject go = piecebackGroundObjectPool.GetFromPool(); go.transform.position = new Vector2(i, -j); gridBackgrounds[i][j] = go.GetComponent <Background>(); } } }
/// <summary> /// Формирует массив слов, который будет записан в устройство /// </summary> /// <returns></returns> private ushort[] GenerateConfigForDevice() { List <byte> byteArr = new List <byte>(); List <ushort> confToDevice = new List <ushort>(); Config915Series conf915 = new Config915Series(SelectedSpeed, BitValues, ParityOdd, ParityExistence, StopBitsCount); SpreadTypeAddress(); byteArr.Add(IOTimeout); byteArr.Add((byte)((Type << 4) + Address)); confToDevice.Add(ArrayExtension.ByteArrayToUshortArray(byteArr.ToArray()).First()); confToDevice.Add(ResponseAwait); confToDevice.Add(conf915.Config); confToDevice.Add(TransmitEnableDelay); confToDevice.Add(TransmitDisableDelay); return(confToDevice.ToArray()); }
public override void OnXGUI() { //TODO List component = CreateObjectField(componentName, component) as Component; if (null != component) { componentName = component.GetType().ToString(); if (CreateSpaceButton("Seach All")) { Component[] components = GameObject.FindObjectsOfType(component.GetType()) as Component[]; GameObject[] goArray = ArrayExtension.AllocArrayFormOther <Component, GameObject>(components); for (int pos = 0; pos < components.Length; pos++) { Debug.Log("pos is " + components[pos].name); goArray[pos] = components[pos].gameObject; } Selection.objects = goArray; } } isPreciseSeach = CreateCheckBox("is Precise Seach", isPreciseSeach); BeginHorizontal(); seachEventByName = CreateStringField("Event Name", seachEventByName); if (CreateSpaceButton("Seach Event")) { seachObjects.Clear(); SeachPlaymakerByEventName(); Selection.objects = seachObjects.ToArray(); } EndHorizontal(); BeginHorizontal(); seachActionByName = CreateStringField("Action Name", seachActionByName); if (CreateSpaceButton("Seach Action")) { seachObjects.Clear(); SeachPlaymakerByActionName(); Selection.objects = seachObjects.ToArray(); } EndHorizontal(); }
/// <summary> /// Создание запроса из свойств экземпляра /// </summary> public void CreateRequest() { try { List <byte> req = new List <byte>(); req.Add(Period); req.Add((byte)((Type << 4) + CrateAddress)); req.Add(Command); req.AddRange(ParameterModuleAddress); req.AddRange(ParameterBaseAddress); req.Add(ParameterCount); Request = ArrayExtension.ByteArrayToUshortArray(req.ToArray()); byte[] reqToDev = req.ToArray(); ArrayExtension.SwapArrayItems(ref reqToDev); RequestToDevice = ArrayExtension.ByteArrayToUshortArray(reqToDev); } catch { } }
public void ProvideValueInconsistent2 () { var x = new ArrayExtension (new int [] {1, 3}); x.AddChild (new object ()); x.AddChild (null); // allowed Assert.AreEqual (4, x.Items.Count); Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null)); }
public void AddToCollectionArrayInstance () { var i = new XamlTypeInvoker (new XamlType (typeof (int []), sctx)); var ax = new ArrayExtension (); i.AddToCollection (ax, 5); }
public void AddToCollectionArrayExtension () { var i = XamlLanguage.Array.Invoker; var ax = new ArrayExtension (); i.AddToCollection (ax, 5); }
public void ProvideValueInconsistent () { var x = new ArrayExtension (typeof (int)); x.AddChild (new object ()); Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null)); }
// takes a BamlCollectionHolder and its context and sets the value of the holder's collection to be // either the default collection instantiated by the holder's constructor or a newly created // collection created based on the expected type. // *** Used when we do not have an explicit tag. private void InitPropertyCollection(BamlCollectionHolder holder, ReaderContextStackData context) { // this method should only be called to initialize the collection Debug.Assert (holder.Collection == null); if (context.ContextType == ReaderFlags.PropertyArray) { // arrays are a little different than other collections, because we wrap them in an array extension. // Here we create an array extension and assign the element type based on the property. ArrayExtension arrayExt = new ArrayExtension(); arrayExt.Type = context.ExpectedType.GetElementType(); holder.Collection = arrayExt; } else if (holder.DefaultCollection != null) { // if we the property getter returned a default value, then we use that collection to insert // as the property's collection. holder.Collection = holder.DefaultCollection; } else { ThrowException(SRID.ParserNullPropertyCollection, holder.PropertyDefinition.Name); } context.ExpectedType = null; // Don't want to receive any other values }
public void AddTextInconsistent () { var x = new ArrayExtension (new int [] {1, 3}); Assert.AreEqual (typeof (int), x.Type, "#1"); x.AddText ("test"); x.AddText (null); // allowed Assert.AreEqual (4, x.Items.Count); Assert.AreEqual (typeof (int), x.Type, "#2"); }
public void ProvideValueInconsistent3 () { var x = new ArrayExtension (new int [] {1, 3}); x.AddText ("test"); Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null)); }
public void Read_ArrayExtension () { var obj = new ArrayExtension (new int [] {5, -3, 0}); var r = new XamlObjectReader (obj); Read_ArrayOrArrayExtension (r, obj); }
public void AddToCollectionArrayInstance () { var i = new XamlTypeInvoker (new XamlType (typeof (int []), sctx)); var ax = new ArrayExtension (); Assert.Throws<NotSupportedException> (() => i.AddToCollection (ax, 5)); }
public void ProvideValueWithoutType () { var x = new ArrayExtension (); x.ProvideValue (null); // Type must be set first. }
public TestClass () { ArrayMember = new ArrayExtension (typeof (int)); ArrayMember.AddChild (5); ArrayMember.AddChild (3); ArrayMember.AddChild (-1); }
public void ProvideValueInconsistent () { var x = new ArrayExtension (typeof (int)); x.AddChild (new object ()); x.ProvideValue (null); }
public void ProvideValueInconsistent3 () { var x = new ArrayExtension (new int [] {1, 3}); x.AddText ("test"); x.ProvideValue (null); }
public void ProvideValueInconsistent2 () { var x = new ArrayExtension (new int [] {1, 3}); x.AddChild (new object ()); x.AddChild (null); // allowed Assert.AreEqual (4, x.Items.Count); x.ProvideValue (null); }
public void ProvideValueWithoutType () { var x = new ArrayExtension (); Assert.Throws<InvalidOperationException> (() => x.ProvideValue (null)); // Type must be set first. }
public void ProvideValue () { var x = new ArrayExtension (new int [] {1, 3}); x.AddChild (5); Assert.AreEqual (3, x.Items.Count); var ret = x.ProvideValue (null); Assert.IsNotNull (ret, "#1"); var arr = ret as int []; Assert.IsNotNull (arr, "#2"); Assert.AreEqual (3, arr.Length, "#3"); Assert.AreEqual (5, arr [2], "#4"); }
public void AddToCollectionArrayExtension () { var i = XamlLanguage.Array.Invoker; var ax = new ArrayExtension (); Assert.Throws<NotSupportedException> (() => i.AddToCollection (ax, 5)); }
public void ProvideValueEmpty () { var x = new ArrayExtension (typeof (int)); x.ProvideValue (null); // allowed. }