/// <summary> /// Processes all testcase events. /// <see cref="AllureCSharpCommons.Events.TestCaseStartedEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCasePendingEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCaseCanceledEvent"/> /// <see cref="AllureCSharpCommons.Events.TestCaseFinishedEvent"/> /// </summary> /// <param name="evt">event to process</param> public void Fire(ITestCaseEvent evt) { if (typeof(TestCaseStartedEvent).IsAssignableFrom(evt.GetType())) { StepStorage.Get(); var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); lock (TestSuiteAddChildLock) { TestSuiteStorage.Put(evt.SuiteUid); TestSuiteStorage.Get(evt.SuiteUid).testcases = ArraysUtils.Add(TestSuiteStorage.Get(evt.SuiteUid).testcases, testcaseresult); } } else if (typeof(TestCaseFinishedEvent).IsAssignableFrom(evt.GetType())) { var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); var root = StepStorage.PollLast(); testcaseresult.steps = ArraysUtils.AddAll(testcaseresult.steps, root.steps); testcaseresult.attachments = ArraysUtils.AddAll(testcaseresult.attachments, root.attachments); StepStorage.Remove(); TestCaseStorage.Remove(); } else { var testcaseresult = TestCaseStorage.Get(); evt.Process(testcaseresult); } }
private void CalculateRequire() { int index = 1; List <IntPair> items; if (config.PayKey == null || config.PayKey.Length == 0) { items = ArraysUtils.GetSubArray(UserProfile.InfoBag.GetItemCountByType((int)HItemTypes.Material), 0, 13); } else { string pickKey = config.PayKey[MathTool.GetRandom(config.PayKey.Length)]; items = ArraysUtils.GetSubArray(UserProfile.InfoBag.GetItemCountByAttribute(pickKey), 0, 13); } for (int i = 0; i < items.Count; i++) { var region = new ButtonRegion(index, pos.X + 3 + 20 + (index - 1) % 7 * 70, pos.Y + 3 + 25 + (index - 1) / 7 * 70, 60, 60, HItemBook.GetHItemImage(items[i].Type)); region.SetKeyValue(items[i].Type); region.AddDecorator(new RegionTextDecorator(37, 42, 12, Color.White, true, items[i].Value.ToString())); vRegion.AddRegion(region); index++; } var button = new ButtonRegion(20, pos.X + 3 + 20 + (index - 1) % 7 * 70, pos.Y + 3 + 25 + (index - 1) / 7 * 70, 60, 60, "iconbg.jpg", ""); button.AddDecorator(new RegionImageDecorator(HSIcons.GetIconsByEName("rot7"), 60 / 2)); vRegion.AddRegion(button); }
protected override string HandleData(string data) { int width = DefaultWidth; int height = DefaultHeight; if (!string.IsNullOrWhiteSpace(data)) { var splitedData = data.Trim().Split().Where(s => !string.IsNullOrEmpty(s)).ToList(); if (splitedData.Count() != 2 || !int.TryParse(splitedData[0], out width) || !int.TryParse(splitedData[1], out height)) { throw new ArgumentException($"parse \"{ data }\" failed", nameof(data)); } } StringBuilder result = new StringBuilder(); result.Append($"Generated array:{ Environment.NewLine }"); var array = ArraysUtils.GenerateArray(new[] { width, height }, () => _rnd.Next(ValueDownLimit, ValueUpLimit)); Add2DArrayToStringBilder(result, array); result.Append($"Sum even elements:{ Environment.NewLine }"); result.Append($"{ CalcEvenElements(array, (int a, int b) => a + b) }{ Environment.NewLine }"); return(result.ToString()); }
protected override string HandleData(string data) { StringBuilder result = new StringBuilder(); result.Append($"Inicializing array:{ Environment.NewLine }"); var array = ArraysUtils.GenerateArray(_degreesLengths, () => _rnd.Next(ValueDownLimit, ValueUpLimit + 1)); AddCubicArrayToStringBilder(result, array); result.Append($"Replacement values:{ Environment.NewLine }"); ArraysUtils.ReplaceElements(array, val => val > 0, 0); AddCubicArrayToStringBilder(result, array); return(result.ToString()); }
public void Init() { foreach (var tacticConfig in ConfigData.BattleTacticDict.Values) { var randMonId = ConfigDataManager.GetRandMonsterId(tacticConfig.Group); itemList.Add(new MatchCellInfo { Id = tacticConfig.CellId, Side = (byte)tacticConfig.Side, IsHide = true, MonsterId = randMonId }); } ArraysUtils.RandomShuffle(itemList); for (int i = 0; i < GameConst.RowCount; i++) { itemList[i].Pos = new NarlonLib.Math.Vector2(i % GameConst.ColumnCount, i / GameConst.ColumnCount); cellMap[itemList[i].Pos.X, itemList[i].Pos.Y] = itemList[i].Id; } }
/// <summary> /// Processes all step events. /// <see cref="AllureCSharpCommons.Events.StepStartedEvent"/> /// <see cref="AllureCSharpCommons.Events.StepCanceledEvent"/> /// <see cref="AllureCSharpCommons.Events.StepFinishedEvent"/> /// </summary> /// <param name="evt">event to process</param> public void Fire(IStepEvent evt) { if (typeof(StepStartedEvent).IsAssignableFrom(evt.GetType())) { var step = new step(); evt.Process(step); StepStorage.Put(step); } else if (typeof(StepFinishedEvent).IsAssignableFrom(evt.GetType())) { var step = StepStorage.PollLast(); evt.Process(step); StepStorage.Last.steps = ArraysUtils.Add(StepStorage.Last.steps, step); } else { var step = StepStorage.Last; evt.Process(step); } }
protected override string HandleData(string data) { int length = DefaultLength; if (!string.IsNullOrWhiteSpace(data)) { if (!int.TryParse(data, out length)) { throw new ArgumentException($"parse \"{ data }\" failed", nameof(data)); } } try { StringBuilder result = new StringBuilder(); result.Append($"Inicializing collection:{ Environment.NewLine }"); var elements = (from int val in ArraysUtils.GenerateArray(new[] { length }, () => _rnd.Next(ValueUpLimit)) select val) .ToList(); elements.ForEach(element => result.Append($"{ element } ")); result.Append(Environment.NewLine); var max = HeaviestElementUtil.GetHeaviestElement(elements, (a, b) => a.CompareTo(b)); result.Append($"Max element searching:{ Environment.NewLine }max = { max }{ Environment.NewLine }"); var min = HeaviestElementUtil.GetHeaviestElement(elements, (a, b) => b.CompareTo(a)); result.Append($"Mix element searching:{ Environment.NewLine }min = { min }{ Environment.NewLine }"); result.Append($"Sorting collection:{ Environment.NewLine }"); SortUtil.Sort(elements); elements.ForEach(element => result.Append($"{ element } ")); result.Append(Environment.NewLine); return(result.ToString()); } catch { throw; } }
protected override string HandleData(string data) { var result = new StringBuilder(); result.Append($"Generated collection:{ Environment.NewLine }"); var collection = (from int element in ArraysUtils .GenerateArray(new[] { DefaultLength }, () => _rnd.Next(ValueDownLimit, ValueUpLimit)) select element) .ToList(); foreach (var element in collection) { result.Append($"{ element } "); } result.Append(Environment.NewLine); result.Append($"Calculated summ:{ Environment.NewLine }"); result.Append(SummByPredicate(collection, element => element > 0, (a, b) => a + b)); return(result.ToString()); }
public static int[] CalculateConnectedComponents(int[] _from, int[] _to, int vertices) { //Test for parameters consistence if (_from.Length != _to.Length) { throw new ArgumentException(); } //No edges case if (_from.Length == 0) { var result = new int[vertices + 1]; for (var i = 0; i < vertices + 1; ++i) { result[i] = i; } return(result); } //Creating sorted union var from = new int[_from.Length << 1]; var to = new int[_from.Length << 1]; Array.Copy(_from, 0, from, 0, _from.Length); Array.Copy(_to, 0, to, 0, _from.Length); Array.Copy(_from, 0, to, _from.Length, _from.Length); Array.Copy(_to, 0, from, _from.Length, _from.Length); //Sorting to easy indexing by from ArraysUtils.quickSort(from, to); //Test for parameters consistence if (from[0] < 0 || from[from.Length - 1] > vertices) { throw new ArgumentException(); } //Creating index for fast search in from array var fromIndex = new int[vertices]; Arrays.fill(fromIndex, -1); //-1 in fromIndex means absence of edges for certain vertex var lastVertex = -1; for (var i = 0; i < from.Length; ++i) { if (lastVertex != from[i]) { fromIndex[lastVertex = from[i]] = i; } } //Allocation resulting array var components = new int[vertices + 1]; Arrays.fill(components, -1); //There will be no -1 at the end var currentComponent = -1; var m1 = 0; var stack = new Stack <BreadthFirstPointer>(); do { ++currentComponent; components[m1] = currentComponent; if (fromIndex[m1] == -1) { //There is no edges for curreent vertex, //so it is connected component by it self continue; } //Pushing seed vertex to stack stack.Push(new BreadthFirstPointer(m1, fromIndex[m1])); //Main algorithm (simple depth-first search) while (stack.Count == 0) { var pointer = stack.Peek(); if (pointer.EdgePointer >= from.Length || from[pointer.EdgePointer++] != pointer.Vertex) { //There are no more edges from this vertex => delete it from stack and continue stack.Pop(); continue; } // -1 because pointer.edgePointer++ was invoked var pointsTo = to[pointer.EdgePointer - 1]; if (components[pointsTo] == currentComponent) { //We've been here earlier, continue continue; } Debug.Assert(components[pointsTo] == -1); //Marking current vertex by current connected component index components[pointsTo] = currentComponent; if (fromIndex[pointsTo] != -1) { //No edges from this vertex stack.Push(new BreadthFirstPointer(pointsTo, fromIndex[pointsTo])); } } } while ((m1 = FirstM1(components)) != vertices); //writing components count components[vertices] = currentComponent + 1; return(components); }
public override void Process(testcaseresult context) { context.parameters = ArraysUtils.Add(context.parameters, new parameter(Name, Value, parameterkind.environmentvariable)); }
public StructureOfContractions(Tensor[] data, int differentIndicesCount, IIndices freeIndices) { //Names (names with type, see IndicesUtils.getNameWithType() ) of all indices in this multiplication //It will be used as index name -> index index [0,1,2,3...] mapping int[] upperIndices = new int[differentIndicesCount], lowerIndices = new int[differentIndicesCount]; //This is sorage for intermediate information about indices, used in the algorithm (see below) //Structure: // ulong[] upperInfo = new ulong[differentIndicesCount], lowerInfo = new ulong[differentIndicesCount]; //This is for generalization of algorithm //indices[0] == lowerIndices //indices[1] == lowerIndices int[][] indices = { lowerIndices, upperIndices }; //This is for generalization of algorithm too //info[0] == lowerInfo //info[1] == lowerInfo ulong[][] info = { lowerInfo, upperInfo }; //Pointers for lower and upper indices, used in algorithm //pointer[0] - pointer to lower //pointer[1] - pointer to upper int[] pointer = new int[2]; //Allocating array for results, one contraction for each tensor contractions = new long[data.Length][]; //There is one dummy tensor with index -1, it represents fake //tensor contracting with whole Product to leave no contracting indices. //So, all "conractions" with this dummy "contraction" looks like a scalar //product. (sorry for English) freeContractions = new long[freeIndices.Size()]; uint state; uint index; uint i; //Processing free indices = creating contractions for dummy tensor for (i = 0; i < freeIndices.Size(); ++i) { index = freeIndices[i]; //Inverse state (because it is state of index at (??) dummy tensor, //contracted with this free index) state = 1 - IndicesUtils.getStateInt(index); //Important: info[state][pointer[state]] = dummyTensorInfo; indices[state][pointer[state]++] = IndicesUtils.GetNameWithType(index); } int tensorIndex; for (tensorIndex = 0; tensorIndex < data.Length; ++tensorIndex) { //Main algorithm IIndices tInds = data[tensorIndex].Indices; short[] diffIds = tInds.GetDiffIds(); //FUTURE move to other place if (tInds.Size() >= 0x10000) { throw new InvalidOperationException("Too many indices!!! max count = 2^16"); } for (uint j = 0; j < tInds.Size(); ++j) { index = tInds[j]; state = IndicesUtils.getStateInt(index); info[state][pointer[state]] = packToLong(tensorIndex, diffIds[j], j); indices[state][pointer[state]++] = IndicesUtils.GetNameWithType(index); } //Result allocation contractions[tensorIndex] = new long[tInds.Size()]; } //Here we can use unstable sorting algorithm (all indices are different) ArraysUtils.quickSort(indices[0], info[0].Select(u => (int)u).ToArray()); ArraysUtils.quickSort(indices[1], info[1].Select(u => (int)u).ToArray()); //Calculating connected components var infoTensorIndicesFrom = infoToTensorIndices(lowerInfo); var infoTensorIndicesTo = infoToTensorIndices(upperInfo); uint shift = 0; uint last = 0; for (i = 0; i < infoTensorIndicesFrom.Length; ++i) { if (infoTensorIndicesFrom[i] == -1 || infoTensorIndicesTo[i] == -1) { Array.Copy(infoTensorIndicesFrom, last, infoTensorIndicesFrom, last - shift, i - last); Array.Copy(infoTensorIndicesTo, last, infoTensorIndicesTo, last - shift, i - last); last = i + 1; ++shift; } } Array.Copy(infoTensorIndicesFrom, last, infoTensorIndicesFrom, last - shift, i - last); Array.Copy(infoTensorIndicesTo, last, infoTensorIndicesTo, last - shift, i - last); infoTensorIndicesFrom = Arrays.copyOf(infoTensorIndicesFrom, (int)(infoTensorIndicesFrom.Length - shift)); infoTensorIndicesTo = Arrays.copyOf(infoTensorIndicesTo, (int)(infoTensorIndicesTo.Length - shift)); int[] components = GraphUtils.CalculateConnectedComponents(infoTensorIndicesFrom, infoTensorIndicesTo, data.Length); componentCount = components[components.Length - 1]; this.components = Arrays.copyOfRange(components, 0, components.Length - 1); //<-- Here we have mature info arrays Debug.Assert(indices[0].SequenceEqual(indices[1])); int freePointer = 0; int indexIndex; for (i = 0; i < differentIndicesCount; ++i) { //Contractions from lower to upper tensorIndex = (int)(0xFFFFFFFFL & (info[0][i] >> 16)); //From tensor index indexIndex = (int)(0xFFFFL & (info[0][i] >> 48)); ulong contraction = (0xFFFFFFFFFFFF0000L & (info[1][i] << 16)) | (0xFFFFL & info[0][i]); if (tensorIndex == -1) { freeContractions[freePointer++] = (long)contraction; } else { contractions[tensorIndex][indexIndex] = (long)contraction; } //Contractions from upper to lower tensorIndex = (int)(0xFFFFFFFFL & (info[1][i] >> 16)); //From tensor index indexIndex = (int)(0xFFFFL & (info[1][i] >> 48)); contraction = (0xFFFFFFFFFFFF0000L & (info[0][i] << 16)) | (0xFFFFL & info[1][i]); if (tensorIndex == -1) { freeContractions[freePointer++] = (long)contraction; } else { contractions[tensorIndex][indexIndex] = (long)contraction; } } }
public override void Process(testcaseresult context) { var attachment = AllureResultsUtils.WriteAttachmentSafely(Attachment, Title, Type); context.attachments = ArraysUtils.Add(context.attachments, attachment); }
public override void Process(step context) { context.attachments = ArraysUtils.Add(context.attachments, Attach); }