public PencilKeyInfo(Pencil.Gaming.Key key, int scancode, KeyAction action, KeyModifiers modifiers) { Key = key; Scancode = scancode; Action = action; Modifiers = modifiers; }
Pencil GetPencil(bool forUndoRedo) { if (!this.pencilEvent.WaitOne()) { throw new InvalidOperationException(); } this.activePencil = new Pencil(this, forUndoRedo); return this.activePencil; }
public bool TryGetPencil(int timeoutMilliseconds, out TextPencil pencil) { if (!this.pencilEvent.WaitOne(timeoutMilliseconds)) { pencil = null; return false; } this.activePencil = new Pencil(this, forUndoRedo: false); pencil = this.activePencil; return true; }
public void EditShouldKeepSpacesIfReplacementIsTooShort() { string inputText = "An apple a day keeps the doctor away"; string expectedText = "An owl a day keeps the doctor away"; string actualText; Pencil pencil = new Pencil(20, 20, 20); pencil.Written = inputText; pencil.Edit("apple", "owl"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
public void EditShouldReplaceErasedTextWithSymbolIfTooLong() { string inputText = "An apple a day keeps the doctor away"; string expectedText = "An artich@k@ay keeps the doctor away"; string actualText; Pencil pencil = new Pencil(20, 20, 20); pencil.Written = inputText; pencil.Edit("apple", "artichoke"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
public void EditShouldReplaceErasedText() { string inputText = "An apple a day keeps the doctor away"; string expectedText = "An onion a day keeps the doctor away"; string actualText; Pencil pencil = new Pencil(20, 20, 20); pencil.Written = inputText; pencil.Edit("apple", "onion"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
public void EraseShouldOnlyEraseCharactersUntilDurabilityIsZero() { string inputText = "Buffalo Bill"; string expectedText = "Buffalo B "; string actualText; Pencil pencil = new Pencil(20, 20, 3); pencil.Written = inputText; pencil.Erase("Bill"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
public void EraseShouldRemoveLastOccurrenceOfString() { string inputText = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"; string expectedText = "How much wood would a woodchuck chuck if a woodchuck could wood?"; string actualText; Pencil pencil = new Pencil(20, 20, 20); pencil.Written = inputText; pencil.Erase("chuck"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
public void SharpenShouldResetDurabilityToChosenValueIfLessThanRemaining() { string expectedText = "Hell Wo "; string actualText; Pencil pencil = new Pencil(8, 5); pencil.Write("Hello"); pencil.Sharpen(5); pencil.Write(" World"); actualText = pencil.Written; Assert.AreEqual(expectedText, actualText); }
[InlineData(6, null, "")] //test writing null public void TestPencilManufacturer(int durability, string textToWrite, string expectedValue) { //Arrange String paper = ""; //Act Pencil pencil = new Pencil(durability, 1); paper = paper + pencil.Write(textToWrite); //Assert Assert.Equal(expectedValue, paper); }
public void WhiteSpacesInGivenInputDoNotReduceDurability() { //Arrange var receipt = new PaperModel(); var highlighter = new Pencil(20); var taxDeductiblePurchase = "office supplies"; var inkLeft = 6; //Act highlighter.WriteInputOntoPaper(taxDeductiblePurchase, receipt); //Assert Assert.AreEqual(inkLeft, highlighter.PencilDurability); }
public void PencilDurabilityFunctionReducesDurabilityByOnePerLetter() { //Arrange var backOfEnvelope = new PaperModel(); var groceryList = "eggs and milk"; var inkLeft = 9; var bicPen = new Pencil(20); //Act bicPen.WriteInputOntoPaper(groceryList, backOfEnvelope); //Assert Assert.AreEqual(inkLeft, bicPen.PencilDurability); }
public void PaperContainsTextPencilWrites() { //Arrange var letterToSanta = "Dear Santa, I hope you're well"; var constructionPaper = new PaperModel(); NumberTwoPencil = new Pencil(); //Act NumberTwoPencil.WriteInputOntoPaper(letterToSanta, constructionPaper); //Assert StringAssert.AreEqualIgnoringCase(letterToSanta, constructionPaper.WrittenContent); }
public void IfDurabilityLowerThanTwoPencilDoesNotWriteCapitalLetter() { //Arrange NumberTwoPencil = new Pencil(1); Paper = new PaperModel(); var capitalLetter = "J"; //Act NumberTwoPencil.WriteInputOntoPaper(capitalLetter, Paper); //Assert Assert.AreNotEqual(capitalLetter, Paper.WrittenContent); Assert.AreEqual(Paper.WrittenContent, "j"); }
public void FourReturnsNewPencil(string userInput) { var paper = new Paper(); var pencil = new Pencil(); var pencilDrawer = new Stack <IWritingUtensil>(); var eraseHelper = new EraseHelper(paper); var editHelper = new EditHelper(paper, pencil); var writeAndSharpenHelper = new WriteAndSharpenHelper(paper, pencil); var sut = new RunApplication(paper, pencil, pencilDrawer, eraseHelper, editHelper, writeAndSharpenHelper); var result = sut.ValidateUserActionRequest(userInput); Assert.True(result == UserActionSelection.newPencil); }
public void Pencil_WhenPointDegradationAtZero_LeavesSpacesOnly() { var paper = new Paper(); var eraser = new Eraser(paper, 20); var pencil = new Pencil(new PencilProperties() { Paper = paper, PointDegradation = 4, MaxNumberOfSharpenings = 1, Eraser = eraser }); pencil.Write("Text"); Assert.AreEqual("Tex ", paper.Text); Assert.IsTrue(pencil.PointDegradationRemaining == 0); }
public ActionResult Create(PencilViewModel model) { var newItem = new Pencil(model.Title, model.Price, model.Description); var buyers = _service.GetAllBuyers(); foreach (var item in model.Buyers) { var sellectedBuyer = buyers.FirstOrDefault(b => b.Id == item); newItem.Buyers.Add(sellectedBuyer); } _service.CreateNewPencil(newItem, model.File.InputStream, model.File.FileName); return(Redirect("/")); }
public void WriteAdjustsDurabilityCorrectilyForWhiteSpaceWithMoreLettersThanDurabilityLeft() { Pencil pencil = new Pencil(tipDurability); string longPhrase = "This Phrase Is More Than Twenty Durability"; //43 total durability expectedString = "This Phrase Is More "; //20 written durability, 26 white spaces (3 no durability white spaces) int expectedTip = 0; actualString = pencil.Write(longPhrase); int actualTip = pencil.Tip; Assert.AreEqual(expectedString, actualString); Assert.AreEqual(expectedTip, actualTip); }
public void Pencil_WhenLettersMatchDegradationCalc_HasDegradationOfZero() { var paper = new Paper(); var eraser = new Eraser(paper, 20); var pencil = new Pencil(new PencilProperties() { Paper = paper, PointDegradation = 4, MaxNumberOfSharpenings = 1, Eraser = eraser }); pencil.Write("text"); Assert.AreEqual("text", paper.Text); Assert.IsTrue(pencil.PointDegradationRemaining == 0); }
public void PencilStopsWritingIfDurabilityEqualOrLessThanZero() { //Arrange NumberTwoPencil = new Pencil(5); Paper = new PaperModel(); var mumble = "what if"; var whatWasHeard = "what i "; //Act NumberTwoPencil.WriteInputOntoPaper(mumble, Paper); //Assert StringAssert.AreEqualIgnoringCase(whatWasHeard, Paper.WrittenContent); }
public void WhenRewritingNothingItDoesNotThrowEx() { var pencil = new Pencil(); var paper = new Paper(); try { pencil.Rewrite(string.Empty, ref paper); } catch { Assert.True(false, "Exception thrown when calling Rewrite"); } }
public void Pencil_WhenWritingSpaces_DoesNotAffectDegradation() { var paper = new Paper(); var eraser = new Eraser(paper, 20); var pencil = new Pencil(new PencilProperties() { Paper = paper, PointDegradation = 10, MaxNumberOfSharpenings = 1, Eraser = eraser }); pencil.Write("a b c"); Assert.AreEqual("a b c", paper.Text); Assert.IsTrue(pencil.PointDegradationRemaining == 7); }
public void WriteCapitalLetterWithOnePointDurabilityReturnsCapitalLetterAnd0Durability() { Pencil pencil = new Pencil(1); expectedString = "T"; expectedInt = 0; actualString = pencil.Write("T"); actualInt = pencil.GetTip(); Assert.AreEqual(expectedInt, actualInt); Assert.AreEqual(expectedString, actualString); }
public void WhenOverwritingThePointDurabilityIsReduced(string text, int expectedResult) { var testString = "An apple a day keeps the doctor away"; var initialDurability = 1000; var pencil = new Pencil(initialDurability, 5, 100); var paper = new Paper(); pencil.Write(testString, ref paper); pencil.Sharpen(); pencil.Erase("apple", ref paper); pencil.Rewrite(text, ref paper); Assert.Equal(initialDurability - expectedResult, pencil.Durability); }
public void SharpenPencilWithZeroLengthDoesNotReturnTipToMaximum() { int zeroPencilLength = 0; Pencil pencil = new Pencil(tipDurability20, zeroPencilLength, eraserDurability10); pencil.Write(singleWord5toWrite4toErase); expectedInt = tipDurabilityAfterSingle15; pencil.Sharpen(); actualInt = pencil.GetTip(); Assert.AreEqual(expectedInt, actualInt); }
void Awake() { instance = this; showColor = new byte[size * size * 4]; material = GetComponent <MeshRenderer>().material; pencil = new Pencil(); pencil.Init(this, size, size, curve); pen = new Pen(); pen.Init(this, size, size, curve); eraser = new Eraser(); eraser.Init(this, size, size, curve); curBrush = pen; layerMgr = LayerMgr.GetInstance(); }
public IHttpActionResult Get(int id) { var DbPencil = db.Pencils.FirstOrDefault(pencilEntity => pencilEntity.PencilId == id); Pencil pencil = new Pencil() { PencilId = DbPencil.PencilId, Price = DbPencil.Price, Description = DbPencil.Description, Image = DbPencil.Image, Name = DbPencil.Name, BuyersIds = DbPencil.Buyers.Select(buyer => buyer.BuyerId) }; return(Ok(pencil)); }
public void CapitalLettersReduceDurabilityByTwo() { //Arrange NumberTwoPencil = new Pencil(20); var barbaricYawp = "MY YAWPS TOP"; Paper = new PaperModel(); var bigWhoppingZero = 0; //Act NumberTwoPencil.WriteInputOntoPaper(barbaricYawp, Paper); //Assert Assert.AreEqual(bigWhoppingZero, NumberTwoPencil.PencilDurability); }
public void WriteReturnsWhiteSpaceifDurabilityRunsOut() { int lowDurability = 2; Pencil pencilLowTip = new Pencil(lowDurability); expectedString = "T "; actualString = pencilLowTip.Write(testInput); // test input is 5 durability. First letter is a capital, requires 2 durability. // expected should be "T " (3 white spaces) Assert.AreEqual(expectedString, actualString); }
public void SharpenPencilWithZeroLengthDoesNotReturnTipToMaximum() { int zeroPencilLength = 0; Pencil pencil = new Pencil(tipDurability, zeroPencilLength, eraser); pencil.Write(testInput); //Starting durability is 20, testInput costs 5 durability expectedInt = 15; pencil.Sharpen(); actualInt = pencil.Tip; Assert.AreEqual(expectedInt, actualInt); }
public void eraseTest() { var writer = new Pencil(); writer.write("How much wood would a woodchuck chuck if a woodchuck could chuck wood?"); Assert.AreEqual(writer.sheet, "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"); // Erase chuck and see if we get what we would expect. writer.erase("chuck"); Assert.AreEqual(writer.sheet, "How much wood would a woodchuck chuck if a woodchuck could wood?"); // Erase chuck again and see if we get what we would expect. writer.erase("chuck"); Assert.AreEqual(writer.sheet, "How much wood would a woodchuck chuck if a wood could wood?"); }
[InlineData(40000, 5, 0, 5)] //Zero sharpenings public void TestPencilWriterSharpenLength(int durability, int pencilLength, int numberOfSharpenings, int expectedLength) { //Arrange Pencil pencil = new Pencil(durability, pencilLength); //Act while (numberOfSharpenings > 0) { numberOfSharpenings--; pencil.Sharpen(); } //Assert Assert.Equal(expectedLength, pencil.Length); }
public void SharpenerMethodSetsDurabilityEqualToOriginalSharpeness() { //Arrange var inputDurability = 100; var sentenceToBeWritten = "Tip toe through the tulips"; Pencil = new Pencil(inputDurability); Paper = new PaperModel(); //Act Pencil.WriteInputOntoPaper(sentenceToBeWritten, Paper); Pencil.Sharpen(); //Assert Assert.AreEqual(inputDurability, Pencil.PencilDurability); }
public TextBuffer(TextData data) { this.TextData = data; this.LastChange = new TextChange { OldTextData = TextData.Empty, NewTextData = data, Replacement = data }; this.Formatter = new TextFormatter(this); this.pencilEvent = new AutoResetEvent(true); // Signalled -- pencil is available this.activePencil = null; this.undoStack = new Stack<TextUndoUnit>(); this.redoStack = new Stack<TextUndoUnit>(); this.undoObservers = new List<ITextUndoObserver>(); }
public static void Main() { var box = new Box(); var moliv = new Pencil("red"); var himikal = new Pen("blue"); var nojica = new Scissors("Plastic"); // Приема като аргумент само Plastic / Iron Console.WriteLine(nojica.Cut()); box.AddItems(moliv, himikal, nojica); foreach (var item in box.Items) { Console.WriteLine(item); } himikal.ChangeState(); Console.WriteLine(himikal); }
static bool IsAssembly(Pencil.IO.Path path) { var ext = path.GetExtension(); return ext == ".dll" || ext == ".exe"; }
void OnPencilDisposed(Pencil pencil, TextDataChangedEventArgs args) { Debug.Assert(pencil == this.activePencil, "Disposing a pencil that isn't the active one."); if (args != null) { if (this.LastChange != null) { this.LastChange.NextChange = args.Change; } TextChange finalChange = args.Change; while (finalChange.NextChange != null) { finalChange = finalChange.NextChange; } this.TextData = finalChange.NewTextData; this.LastChange = finalChange; var handler = this.TextDataChanged; if (handler != null) { handler(this, args); } if (pencil.UndoUnit != null) { var now = DateTime.Now; bool merged = false; if (((now - this.timeOfLastEdit).TotalMilliseconds < MinimumMillisecondsTimeBetweenUndoUnits) && (this.undoStack.Count > 0)) { // If possible, merge this unit with the one on the stack. TextUndoUnit existingUnit = this.undoStack.Peek(); TextUndoUnit incomingUnit = pencil.UndoUnit; if (incomingUnit.Metadata != null && incomingUnit.Metadata.TryMerge(existingUnit.Metadata)) { // Successful merge existingUnit.Metadata = incomingUnit.Metadata; existingUnit.Merge(pencil.UndoUnit); merged = true; } } if (!merged) { this.undoStack.Push(pencil.UndoUnit); } this.redoStack.Clear(); this.timeOfLastEdit = now; } } this.activePencil = null; this.pencilEvent.Set(); }