public void GameStateChange_TagChange() { TagChange tagChange = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => tagChange = args as TagChange; parser.Parse(new Line("Power", "D 00:31:50.8318211 PowerTaskList.DebugPrintPower() - TAG_CHANGE Entity=Epix tag=RESOURCES_USED value=2")); Assert.IsNotNull(tagChange); Assert.IsNull(tagChange.EntityId); Assert.AreEqual("Epix", tagChange.EntityName); Assert.AreEqual(GameTag.RESOURCES_USED, tagChange.Tag); Assert.AreEqual(2, tagChange.Value); parser.Parse(new Line("Power", "D 00:31:50.8318211 PowerTaskList.DebugPrintPower() - TAG_CHANGE Entity=2 tag=RESOURCES_USED value=2")); Assert.IsNotNull(tagChange); Assert.AreEqual(2, tagChange.EntityId); Assert.AreEqual(GameTag.RESOURCES_USED, tagChange.Tag); Assert.AreEqual(2, tagChange.Value); tagChange = null; parser.Parse(new Line("Power", "D 00:31:50.8568882 PowerTaskList.DebugPrintPower() - TAG_CHANGE Entity=[entityName=Vilefin Inquisitor id=60 zone=HAND zonePos=4 cardId=OG_006 player=2] tag=ZONE value=PLAY")); Assert.IsNotNull(tagChange); Assert.AreEqual(60, tagChange.EntityId); Assert.AreEqual(GameTag.ZONE, tagChange.Tag); Assert.AreEqual((int)Zone.PLAY, tagChange.Value); }
public void GameStateChange_Entity_PredictedCardId() { FullEntity entity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => entity = args as FullEntity; parser.Parse(new Line("Power", "D 00:31:50.9114028 PowerTaskList.DebugPrintPower() - BLOCK_START BlockType=POWER Entity=[entityName=King Togwaggle id=60 zone=PLAY zonePos=2 cardId=LOOT_541 player=2] EffectCardId= EffectIndex=0 Target=0 SubOption=-1")); parser.Parse(new Line("Power", "D 00:32:08.3649436 PowerTaskList.DebugPrintPower() - FULL_ENTITY - Updating [entityName=UNKNOWN ENTITY [cardType=INVALID] id=61 zone=HAND zonePos=0 cardId= player=1] CardID=")); Assert.IsNotNull(entity); Assert.AreEqual(CardIds.NonCollectible.Neutral.KingTogwaggle_KingsRansomToken, entity.Data.CardId); }
public void CreateGame() { var createGame = 0; var parser = new PowerParser(new MockGameInfo()); parser.CreateGame += () => createGame++; parser.Parse(new Line("Power", "D 00:29:50.5743926 GameState.DebugPrintPower() - CREATE_GAME")); Assert.AreEqual(1, createGame); parser.Parse(new Line("Power", "D 00:29:52.6023387 PowerTaskList.DebugPrintPower() - CREATE_GAME")); Assert.AreEqual(1, createGame); }
public void BlockStart_CanParseAllLines() { var validType = 0; var validTarget = 0; var data = TestData.Load("LogTests/TestData/data_1.json"); var lines = File.ReadLines(data.LogFile).Where(x => x.Contains("PowerTaskList") && x.Contains("BLOCK_START")).ToList(); var targets = lines.Where(x => x.Contains("Target=") && !x.Contains("Target=0") && !x.Contains("Target= ")).ToList(); var parser = new PowerParser(new MockGameInfo()); parser.BlockStart += args => { if (args.Type != null) { validType++; } if (args.Target != null && args.Target.Id > 0) { validTarget++; } }; foreach (var line in lines) { parser.Parse(new Line("Power", line)); } Assert.AreEqual(197, lines.Count); Assert.AreEqual(197, validType); Assert.AreEqual(19, targets.Count); Assert.AreEqual(19, validTarget); }
public void SetupComplete() { var count = 0; var parser = new PowerParser(new MockGameInfo()); parser.SetupComplete += () => count++; parser.Parse(new Line("Power", "D 00:29:52.5947934 PowerTaskList.DebugDump() - ID=1 ParentID=0 PreviousID=0 TaskCount=88")); Assert.AreEqual(0, count); parser.Parse(new Line("Power", "D 00:29:55.3363610 PowerTaskList.DebugDump() - ID=2 ParentID=0 PreviousID=0 TaskCount=40")); Assert.AreEqual(1, count); parser.Parse(new Line("Power", "D 00:29:56.0075931 PowerTaskList.DebugDump() - ID=22 ParentID=0 PreviousID=0 TaskCount=1")); Assert.AreEqual(1, count); }
public void BlockEnd() { var blockEnd = false; var parser = new PowerParser(new MockGameInfo()); parser.BlockEnd += block => blockEnd = true; parser.Parse(new Line("Power", "D 00:30:21.2050280 PowerTaskList.DebugPrintPower() - BLOCK_END")); Assert.IsTrue(blockEnd); }
public void GameStateChange_HideEntity() { HideEntity hideEntity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => hideEntity = args as HideEntity; parser.Parse(new Line("Power", "D 00:30:21.1930218 PowerTaskList.DebugPrintPower() - HIDE_ENTITY - Entity=[entityName=Divine Favor id=70 zone=HAND zonePos=3 cardId=EX1_349 player=2] tag=ZONE value=DECK")); Assert.IsNotNull(hideEntity); Assert.AreEqual(70, hideEntity.EntityId); }
public void GameStateChange_ChangeEntity() { ChangeEntity changeEntity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => changeEntity = args as ChangeEntity; parser.Parse(new Line("Power", "D 13:14:00.5727617 PowerTaskList.DebugPrintPower() - CHANGE_ENTITY - Updating Entity=[entityName=Shifting Scroll id=28 zone=HAND zonePos=7 cardId=LOOT_104 player=1] CardID=UNG_948")); Assert.IsNotNull(changeEntity); Assert.AreEqual(28, changeEntity.EntityId); Assert.AreEqual("UNG_948", changeEntity.CardId); }
public void GameStateChange_ShowEntity() { ShowEntity showEntity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => showEntity = args as ShowEntity; parser.Parse(new Line("Power", "D 00:30:21.0673837 PowerTaskList.DebugPrintPower() - SHOW_ENTITY - Updating Entity=[entityName=UNKNOWN ENTITY [cardType=INVALID] id=72 zone=DECK zonePos=0 cardId= player=2] CardID=UNG_015")); Assert.IsNotNull(showEntity); Assert.AreEqual(72, showEntity.EntityId); Assert.AreEqual("UNG_015", showEntity.CardId); }
public void BlockStart() { IBlockData blockData = null; var parser = new PowerParser(new MockGameInfo()); parser.BlockStart += args => blockData = args; parser.Parse(new Line("Power", "D 00:33:01.7253587 PowerTaskList.DebugPrintPower() - BLOCK_START BlockType=ATTACK Entity=[entityName=Vilefin Inquisitor id=60 zone=PLAY zonePos=2 cardId=OG_006 player=2] EffectCardId= EffectIndex=0 Target=[entityName=Jade Spirit id=40 zone=PLAY zonePos=2 cardId=CFM_715 player=1] SubOption=-1")); Assert.IsNotNull(blockData); Assert.AreEqual("OG_006", blockData.CardId); Assert.AreEqual(60, blockData.Id); Assert.IsNotNull(blockData.Target); Assert.AreEqual(40, blockData.Target.Id); Assert.AreEqual("CFM_715", blockData.Target.CardId); Assert.AreEqual(BlockType.ATTACK, blockData.Type); blockData = null; parser.Parse(new Line("Power", "D 00:33:04.6148508 PowerTaskList.DebugPrintPower() - BLOCK_START BlockType=TRIGGER Entity=Epix EffectCardId= EffectIndex=-1 Target=0 SubOption=-1 TriggerKeyword=0")); Assert.IsNotNull(blockData); Assert.IsNull(blockData.Target); Assert.AreEqual(BlockType.TRIGGER, blockData.Type); }
public void GameStateChange_TagChange_CreationTag() { TagChange tagChange = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => tagChange = args as TagChange; parser.Parse(new Line("Power", "D 00:31:50.9189508 PowerTaskList.DebugPrintPower() - tag=CONTROLLER value=2")); Assert.IsNotNull(tagChange); Assert.IsTrue(tagChange.CreationTag); Assert.AreEqual(GameTag.CONTROLLER, tagChange.Tag); Assert.AreEqual(2, tagChange.Value); }
public void GameStateChange_Entity() { FullEntity entity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => entity = args as FullEntity; parser.Parse(new Line("Power", "D 00:29:52.7090966 PowerTaskList.DebugPrintPower() - FULL_ENTITY - Updating [entityName=UNKNOWN ENTITY [cardType=INVALID] id=4 zone=DECK zonePos=0 cardId= player=1] CardID=")); Assert.IsNotNull(entity); Assert.IsNotNull(entity.Data); Assert.AreEqual(4, entity.Data.Id); Assert.AreEqual(string.Empty, entity.Data.CardId); Assert.AreEqual(Zone.DECK, entity.Data.Zone); }
public void GameStateChange_GameEntity() { FullEntity entity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => entity = args as FullEntity; parser.Parse(new Line("Power", "D 00:29:52.6063231 PowerTaskList.DebugPrintPower() - GameEntity EntityID=1")); Assert.IsNotNull(entity); var data = entity.Data as GameEntityData; Assert.IsNotNull(data); Assert.AreEqual(1, data.Id); }
public void GameStateChange_PlayerEntity() { FullEntity entity = null; var parser = new PowerParser(new MockGameInfo()); parser.GameStateChange += args => entity = args as FullEntity; parser.Parse(new Line("Power", "D 00:29:52.6665096 PowerTaskList.DebugPrintPower() - Player EntityID=3 PlayerID=2 GameAccountId=[hi=144115198130930503 lo=15856412]")); Assert.IsNotNull(entity); var data = entity.Data as PlayerEntityData; Assert.IsNotNull(data); Assert.AreEqual(2, data.PlayerId); Assert.AreEqual(3, data.Id); }
public static TMeasurement Parse <TMeasurement>(double value, string type) where TMeasurement : IMeasurement { var runtimeType = typeof(TMeasurement); if (runtimeType == typeof(IEnergy)) { return((TMeasurement)EnergyParser.Parse(value, type)); } if (runtimeType == typeof(IPower)) { return((TMeasurement)PowerParser.Parse(value, type)); } if (runtimeType == typeof(IRatio)) { return((TMeasurement)RatioParser.Parse(value, type)); } if (runtimeType == typeof(ITemperature)) { return((TMeasurement)TemperatureParser.Parse(value, type)); } if (runtimeType == typeof(IHumidity)) { return((TMeasurement)HumidityParser.Parse(value, type)); } if (runtimeType == typeof(IIlluminance)) { return((TMeasurement)IlluminanceParser.Parse(value, type)); } if (runtimeType == typeof(IMeasurement)) { return((TMeasurement)(IMeasurement) new ReadOnlyMeasurement(value, type)); } throw new Exception("Could not determine type " + runtimeType.Name); }
public void ItDoesNotThrowAnExceptionWhenParsingValidValues(string input) { PowerParser.Parse(input); }
public void ItParsesTheValueProperly(string input, double expected) { var result = PowerParser.Parse(input); Assert.That(result.Value, Is.EqualTo(expected)); }
public void ItParsesTheTypeProperly(string input, Type type) { var result = PowerParser.Parse(input); Assert.That(result.GetType(), Is.EqualTo(type)); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; if (!ParserHelper.IsKeyword(list[index], "for")) { return(false); } else { // ignored } offset += 1; index = position + offset; if (list[index].type != Expression.Type.Word) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "=")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (FunctionAParser.Parse(context, index)) { ; } while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } while (ConcatParser.Parse(context, index)) { ; } while (LessParser.Parse(context, index)) { ; } while (GreaterParser.Parse(context, index)) { ; } while (LessEqualParser.Parse(context, index)) { ; } while (GreaterEqualParser.Parse(context, index)) { ; } while (EqualParser.Parse(context, index)) { ; } while (NotEqualParser.Parse(context, index)) { ; } while (AndParser.Parse(context, index)) { ; } while (OrParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], ",")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (FunctionAParser.Parse(context, index)) { ; } while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } while (ConcatParser.Parse(context, index)) { ; } while (LessParser.Parse(context, index)) { ; } while (GreaterParser.Parse(context, index)) { ; } while (LessEqualParser.Parse(context, index)) { ; } while (GreaterEqualParser.Parse(context, index)) { ; } while (EqualParser.Parse(context, index)) { ; } while (NotEqualParser.Parse(context, index)) { ; } while (AndParser.Parse(context, index)) { ; } while (OrParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsKeyword(list[index], "do")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (ModuleParser.Parse(context, index)) { ; } if (list[index].type != Expression.Type.Module) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsKeyword(list[index], "end")) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateFor(list, position, offset)); context.Remove(position + 1, offset); return(true); }
public static bool Parse(SyntaxContext context, int position) { var list = context.list; var offset = 0; var index = position; var count = 0; var isMissed = false; while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; if (!ParserHelper.IsOperator(list[index], "<")) { return(false); } else { // ignored } offset += 1; index = position + offset; while (ParenParser.Parse(context, index)) { ; } while (TableIParser.Parse(context, index)) { ; } while (TableSParser.Parse(context, index)) { ; } while (ListParser.Parse(context, index)) { ; } while (PropertyParser.Parse(context, index)) { ; } while (IndexParser.Parse(context, index)) { ; } while (CallParser.Parse(context, index)) { ; } while (NotParser.Parse(context, index)) { ; } while (LengthParser.Parse(context, index)) { ; } while (NegateParser.Parse(context, index)) { ; } while (PowerParser.Parse(context, index)) { ; } while (MultiplyParser.Parse(context, index)) { ; } while (DivisionParser.Parse(context, index)) { ; } while (ModParser.Parse(context, index)) { ; } while (AddParser.Parse(context, index)) { ; } while (SubtractParser.Parse(context, index)) { ; } if (!list[index].isRightValue) { return(false); } else { // ignored } offset += 1; index = position + offset; context.Insert(position, ExpressionCreator.CreateLess(list, position, offset)); context.Remove(position + 1, offset); return(true); }
public void ItThrowsAnExceptionWhenParsingInvalidValues(string input) { PowerParser.Parse(input); }