public void NumberAtomTest() { DiceParser parser = Setup("3"); DiceParser.AtomContext context = parser.atom(); DiceVisitor visitor = new DiceVisitor(); Atom result = (Atom)visitor.VisitAtom(context); result.IsModifier.Should().BeTrue(); result.Sign.Should().Be(AtomSign.Plus); result.ModifierInstance.Should().Be(3); }
public void DiceGroupAtomTest() { DiceParser parser = Setup("2d6"); DiceParser.AtomContext context = parser.atom(); DiceVisitor visitor = new DiceVisitor(); Atom result = (Atom)visitor.VisitAtom(context); result.IsDiceGroup.Should().BeTrue(); result.Sign.Should().Be(AtomSign.Plus); result.DiceGroupInstance.Should().BeEquivalentTo(new DiceGroup(new List <Dice> { new Dice(6), new Dice(6) })); }
public override object VisitAtom([NotNull] DiceParser.AtomContext context) { Atom atom = new Atom(); if (context.diceGroup() == null) { atom.SetModifier(int.Parse(context.NUMBER().GetText())); return(atom); } else { DiceGroup diceGroup = (DiceGroup)this.VisitDiceGroup(context.diceGroup()); atom.SetDiceGroup(diceGroup); return(atom); } }