Beispiel #1
0
		public void AddInstructions()
		{
			IntelInstructionComparer cmp = new IntelInstructionComparer();
			var trie = new InstructionTrie<IntelInstruction>(cmp, cmp);
			IntelInstruction inst = CreatePush(Registers.bp);
			
			trie.AddInstructions(new [] { inst });
			Assert.AreEqual(trie.Count, 1);

			trie.AddInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) });
			Assert.AreEqual(trie.Count, 3);
		}
Beispiel #2
0
		public void ScoreInstructions()
		{
			IntelInstructionComparer cmp = new IntelInstructionComparer();
			var trie = new InstructionTrie<IntelInstruction>(cmp, cmp);
			trie.AddInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) });
			trie.AddInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di) });

			long score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp) });
			Assert.AreEqual(2, score);
			score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp) } );
			Assert.AreEqual(4, score);

			// This sequqnce matches one of the trie's strings exactly.
			score = trie.ScoreInstructions(new  [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di) });
			Assert.AreEqual(6, score);

			// A longer sequence runs 'off' the trie, so it should have the same score
			// as the previous test
			score = trie.ScoreInstructions(new [] {
				CreatePush(Registers.bp),
				CreateMov(Registers.bp, Registers.sp),
				CreatePush(Registers.si),
				CreatePush(Registers.di),
				CreatePush(Registers.bx)});
			Assert.AreEqual(6, score);

			// This doesn't exist in the trie at all, so it should score 0.

			score = trie.ScoreInstructions(new [] {
				CreateMov(Registers.ax, Registers.bx) });
			Assert.AreEqual(0, score);
		}
Beispiel #3
0
		public void Creation()
		{
			IntelInstructionComparer cmp = new IntelInstructionComparer();
			var trie = new InstructionTrie<IntelInstruction>(cmp, cmp);
		}