public async Task <IActionResult> PutPlusOne([FromRoute] int id, [FromBody] PlusOne plusOne) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != plusOne.Id) { return(BadRequest()); //TODO: Add error message here? } _context.Entry(plusOne).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlusOneExists(id)) { return(NotFound()); } throw; } return(NoContent()); }
public void Given_an_array_when_plus_one_then_the_value_should_be_added( int[] inputArray, int[] expected) { var solution = new PlusOne(); var actual = solution.Plus(inputArray).ToArray(); Assert.Equal(expected, actual); }
public void Given_9_When_add_Then_return_10() { var digits = new int[] { 9 }; var result = new int[] { 1, 0 }; Assert.AreEqual(result, PlusOne.GetPlusOne(digits)); }
void InternalTest(int[] num, int[] expected) { int[] actual = PlusOne.Solve(num); Assert.Equal <int>(expected.Length, actual.Length); for (int i = 0; i < actual.Length; i++) { Assert.Equal <int>(expected[i], actual[i]); } }
public void Excution1Test() { var func = new PlusOne(); Assert.IsTrue(Common.AreEqual(new[] { 1, 0, 0, 0 }, func.Excution1(new[] { 9, 9, 9 }))); Assert.IsTrue(Common.AreEqual(new[] { 1, 2, 4 }, func.Excution1(new[] { 1, 2, 3 }))); Assert.IsTrue(Common.AreEqual(new[] { 4, 3, 2, 2 }, func.Excution1(new[] { 4, 3, 2, 1 }))); Assert.IsTrue(Common.AreEqual(new[] { 1 }, func.Excution1(new[] { 0 }))); Assert.IsTrue(Common.AreEqual(new[] { 1, 0 }, func.Excution1(new[] { 9 }))); }
public void TestPlusOne() { var r = PlusOne.Calc(new [] { 1, 2, 3, 4 }); Assert.AreEqual(r.Length, 4); r = PlusOne.Calc(new[] { 9, 9, 9, 9 }); Assert.AreEqual(r.Length, 5); r = PlusOne.Calc(new[] { 9, 4, 9, 9 }); Assert.AreEqual(r.Length, 4); }
public async Task <IActionResult> PostPlusOne([FromBody] PlusOne plusOne) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.PlusOne.Add(plusOne); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPlusOne", new { id = plusOne.Id }, plusOne)); }
public void AddOne1_Passnull_ThrowsException() { Exception exception = null; try { PlusOne.AddOne1(null); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); }
public void AddOne_PassNothing_ThrowsException() { Exception exception = null; try { PlusOne.AddOne(); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); }
public void ApprovePlusOne(int dinnerID, int plusOneID) { Dinner dinner = db.Dinner.Where(d => d.DinnerID == dinnerID).FirstOrDefault(); PlusOne plusOne = db.PlusOnes.Where(p => p.PlusOneID == plusOneID).FirstOrDefault(); plusOne.WaitList = 0; dinner.WaitList--; dinner.Budget += dinner.CostPerPerson; if (dinner.Limit > 0) { dinner.Limit--; } db.SaveChanges(); }
public async Task <IActionResult> DeletePlusOne([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PlusOne po = _context.PlusOne.SingleOrDefault(p => p.Id == id); if (po == null) { return(NotFound()); } _context.PlusOne.Remove(po); await _context.SaveChangesAsync(); return(Ok(po)); }
public void RemovePlusOne(int plusOneID, int dinnerID) { PlusOne plusOne = db.PlusOnes.Where(p => p.PlusOneID == plusOneID).FirstOrDefault(); Dinner dinner = db.Dinner.Where(d => d.DinnerID == plusOne.DinnerID).FirstOrDefault(); if (plusOne != null) { if (dinner.DinnerVoting && dinner.WaitList == 0) { dinner.Limit++; dinner.Budget -= dinner.CostPerPerson; db.Remove(plusOne); db.SaveChanges(); } else if (dinner.WaitList > 0) { dinner.WaitList--; db.Remove(plusOne); db.SaveChanges(); } } }
// A lot of this code is ripped from DuckGame.DM.AddPoints // PlayHooky currently doesn't support calling the original method, and it's honestly a lot easier to patch this code than run before or after it anyway // Please don't sue me, Corptron or Adult Swim public static List <Profile> AddPointsHook(DM t) { List <Profile> profileList = new List <Profile>(); List <Team> teamList = new List <Team>(); List <Team> source = new List <Team>(); foreach (Team team in Teams.all) { foreach (Profile activeProfile in team.activeProfiles) { if (activeProfile.duck != null && !activeProfile.duck.dead) { if (activeProfile.duck.converted != null && activeProfile.duck.converted.profile.team != activeProfile.team) { if (!source.Contains(activeProfile.duck.converted.profile.team)) { source.Add(activeProfile.duck.converted.profile.team); } if (!teamList.Contains(activeProfile.duck.profile.team)) { teamList.Add(activeProfile.duck.profile.team); break; } break; } if (!source.Contains(team)) { source.Add(team); break; } break; } } } if (source.Count <= 1 && source.Count > 0) { source.AddRange((IEnumerable <Team>)teamList); byte winteam = 4; List <int> idxs = new List <int>(); GameMode.lastWinners.Clear(); bool hasSetVibePower = false; foreach (Team team in source) { foreach (Profile activeProfile in team.activeProfiles) { if (activeProfile.duck != null && !activeProfile.duck.dead) { FieldInfo fEditorTestMode = t.GetType().GetField("_editorTestMode", BindingFlags.NonPublic | BindingFlags.Instance); bool _editorTestMode = (bool)fEditorTestMode.GetValue(t); if (!_editorTestMode) { if (Teams.active.Count > 1 && Network.isActive && activeProfile.connection == DuckNetwork.localConnection) { DuckNetwork.GiveXP("Rounds Won", 1, 4, 4, 10, 20, 9999999); if (!hasSetVibePower) { Debug.Log("[DGBP] Local player won!"); RemoveVibePower(); hasSetVibePower = true; } } activeProfile.stats.lastWon = DateTime.Now; ++activeProfile.stats.matchesWon; } profileList.Add(activeProfile); Profile p = activeProfile; if (activeProfile.duck.converted != null) { p = activeProfile.duck.converted.profile; winteam = p.networkIndex; } GameMode.lastWinners.Add(activeProfile); PlusOne plusOne = new PlusOne(0.0f, 0.0f, p, false); plusOne.anchor = (Anchor)((Thing)activeProfile.duck); plusOne.anchor.offset = new Vec2(0.0f, -16f); idxs.Add((int)activeProfile.duck.netProfileIndex); Level.Add((Thing)plusOne); } } } if (Network.isActive && Network.isServer) { Send.Message((NetMessage) new NMAssignWin(idxs, winteam)); } ++source.First <Team>().score; if (!hasSetVibePower && Network.isActive) { Debug.Log("[DGBP] Remote player won!"); AddVibePower(); } } return(profileList); }
public void BeforeEach() { plusOne = new PlusOne(); }
public void AddOne1_Pass1_Returns2() { Assert.AreEqual(2, PlusOne.AddOne1(1)); }
public void AddOne1_Pass999_Returns1000() { Assert.AreEqual(1000, PlusOne.AddOne1(9, 9, 9)); }
public void AddOne_Pass123_Returns124() { Assert.AreEqual(124, PlusOne.AddOne(1, 2, 3)); }
public void PlusOne_0_1() { var actual = new PlusOne().Plus1(new [] { 0 }); CollectionAssert.AreEqual(new [] { 1 }, actual, System.String.Join(',', actual)); }
public void PlusOne_9999_10000() { var actual = new PlusOne().Plus1(new [] { 9, 9, 9, 9 }); CollectionAssert.AreEqual(new [] { 1, 0, 0, 0, 0 }, actual, System.String.Join("", actual)); }
public DoShould() { _plusOne = new PlusOne(); }
public void AddOne1_Pass1234_Returns1235() { Assert.AreEqual(1235, PlusOne.AddOne1(1, 2, 3, 4)); }
public void AddOne1_Pass11_Returns12() { Assert.AreEqual(12, PlusOne.AddOne1(1, 1)); }
public void TestSolution(int[] input1, int[] expectedResult) { var result = new PlusOne().Resolve(input1); Assert.AreEqual(expectedResult, result); }
public int[] PlusOne(int[] digits) { var plusOne = new PlusOne(digits); return(plusOne.SolutionOne()); }