public async Task FetchNonObligatedWeeeForReturnWithoutDuplicates_FetchesOnlySpecifiedReturnWeee() { // Arrange int numberWeeeToCreate = CategoryCount * 2; // Arrange Return to fetch var existingNonObligatedWeees = Enumerable.Range(0, numberWeeeToCreate).Select(n => new NonObligatedWeeeWrapper(Guid.NewGuid(), aatfReturn, 1 + (n % CategoryCount), n > (CategoryCount - 1), (1 + n) * 15)); // Arrange another Return data var otherAatfReturn = new ReturnWrapper(Guid.NewGuid()); var existingNonObligatedWeeesOtherReturn = Enumerable.Range(0, numberWeeeToCreate).Select(n => new NonObligatedWeeeWrapper(Guid.NewGuid(), otherAatfReturn, 1 + (n % CategoryCount), n > (CategoryCount - 1), (1 + n) * 200)); // Build the Repo collection var repoWeee = existingNonObligatedWeees.Concat(existingNonObligatedWeeesOtherReturn); var saveCall = A.CallTo(() => context.SaveChangesAsync()); var dcfNonObligatedWeee = dbContextHelper.GetAsyncEnabledDbSet <NonObligatedWeee>(repoWeee); A.CallTo(() => context.NonObligatedWeee).Returns(dcfNonObligatedWeee); // Act var response = await dataAccess.FetchAllNonObligateWeeeForReturn(aatfReturn.Id); // Assert saveCall.MustNotHaveHappened(); Assert.Equal(numberWeeeToCreate, response.Count()); Assert.False(response.Any(n => n.ReturnId != aatfReturn.Id)); Assert.False(response.Any(n => n.ReturnId == otherAatfReturn.Id)); }
//reference to Q39(Similar) public static int getLongestDistance(TreeAndGraph.BinaryTreeNode root, TreeAndGraph.BinaryTreeNode left, TreeAndGraph.BinaryTreeNode right) { ReturnWrapper wr = getLongestDistanceHelper(root, left, right); //left or right is root will done separately if (wr.findleft && wr.findright) { return(wr.count); } else { return(-1); } }
/// <summary> /// If a function has no inputs and one output, this function will iteratively /// call these outputs until this is no longer the case. This avoids having to specify 'return' outputs /// and suchlike in the source code. /// </summary> public static IFunction ResolveReturns(this IFunction function, CompilationContext info, CallSite?callSite) { while (function?.Inputs?.Length == 0 && function.Outputs?.Length == 1 && function.Outputs[0].Name == "return") { if (info.Debug && !(function is IType)) { function = new ReturnWrapper(function, info, callSite); } else { function = function.Call(function.Outputs[0].Name, info); } } return(function); }
/// <summary> /// If a function has no inputs and one output, this function will iteratively /// call these outputs until this is no longer the case. This avoids having to specify 'return' outputs /// and suchlike in the source code. /// </summary> public static IFunction ResolveReturns(this IFunction function, CompilationContext context, TraceSite?callSite) { while (function?.Inputs?.Length == 0 && function.Outputs?.Length == 1 && function.Outputs[0].Name == "return") { if (/*context.Input.Debug &&*/ !(function is IType)) { function = new ReturnWrapper(function, context, callSite); } else { function = function.Call(function.Outputs[0].Name, context); } } return(function); }
public static ReturnWrapper getLongestDistanceHelper(TreeAndGraph.BinaryTreeNode root, TreeAndGraph.BinaryTreeNode left, TreeAndGraph.BinaryTreeNode right) { if (root == null) { return new ReturnWrapper(); } //if (root == left) //{ // ReturnWrapper rw = new ReturnWrapper(); // rw.findleft = true; // return rw; //} //else if (root == right) //{ // ReturnWrapper rw = new ReturnWrapper(); // rw.findright=true; // return rw; //} ReturnWrapper left_wrapper = getLongestDistanceHelper(root.LeftNode, left, right); if (left_wrapper.findleft && left_wrapper.findright) { return left_wrapper; } else if (left_wrapper.findleft || left_wrapper.findright) { ++left_wrapper.count; } ReturnWrapper right_wrapper = getLongestDistanceHelper(root.RightNode, left, right); if (right_wrapper.findleft && right_wrapper.findright) { return right_wrapper; } else if (right_wrapper.findleft || right_wrapper.findright) { ++right_wrapper.count; } ReturnWrapper wr = new ReturnWrapper(); wr.count = left_wrapper.count + right_wrapper.count; if (root == left) { wr.findleft = true; } else { wr.findleft = left_wrapper.findleft ? left_wrapper.findleft : right_wrapper.findleft; } if (root == right) { wr.findright = true; } else { wr.findright = left_wrapper.findright ? left_wrapper.findright : right_wrapper.findright; } return wr; }
public static ReturnWrapper getLongestDistanceHelper(TreeAndGraph.BinaryTreeNode root, TreeAndGraph.BinaryTreeNode left, TreeAndGraph.BinaryTreeNode right) { if (root == null) { return(new ReturnWrapper()); } //if (root == left) //{ // ReturnWrapper rw = new ReturnWrapper(); // rw.findleft = true; // return rw; //} //else if (root == right) //{ // ReturnWrapper rw = new ReturnWrapper(); // rw.findright=true; // return rw; //} ReturnWrapper left_wrapper = getLongestDistanceHelper(root.LeftNode, left, right); if (left_wrapper.findleft && left_wrapper.findright) { return(left_wrapper); } else if (left_wrapper.findleft || left_wrapper.findright) { ++left_wrapper.count; } ReturnWrapper right_wrapper = getLongestDistanceHelper(root.RightNode, left, right); if (right_wrapper.findleft && right_wrapper.findright) { return(right_wrapper); } else if (right_wrapper.findleft || right_wrapper.findright) { ++right_wrapper.count; } ReturnWrapper wr = new ReturnWrapper(); wr.count = left_wrapper.count + right_wrapper.count; if (root == left) { wr.findleft = true; } else { wr.findleft = left_wrapper.findleft ? left_wrapper.findleft : right_wrapper.findleft; } if (root == right) { wr.findright = true; } else { wr.findright = left_wrapper.findright ? left_wrapper.findright : right_wrapper.findright; } return(wr); }