public void ShouldNotSetEvidencesOnEmptyQuery() { var query = Fix.CreateDefaultQuery(); _uut.Query(query); var actual = _network.GetAllNodes().All(id => !_network.IsEvidence(id)); Assert.IsTrue(actual); }
public void ShouldRemoveStoredCallsFromPreviousQueries() { // place a query that includes a call... var query = Fix.CreateDefaultQuery(); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Execute()LVoid;")); _uut.Query(query); // ...then fall back to a default case ShouldProduceOrderedProposals(); }
public void ShouldSetEvidenceOnCallSite() { var query = Fix.CreateDefaultQuery(); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Init()LVoid;")); _uut.Query(query); var actual = _network.GetEvidenceId(SmilePBNRecommender.ConvertToLegalSmileName("C_LType.Init()LVoid;")); Assert.AreEqual(Constants.StateTrue, actual); }
public void Load_HappyPath() { var a = Fix.CreateNetwork(); var b = Fix.CreateNetwork(); Assert.AreEqual(a, b); var actual = _sut.Load(SomeType()); var expected = new SmilePBNRecommender(SomeType(), Fix.CreateNetwork()); Assert.AreEqual(expected, actual); }
public void ShouldNotProduceAnyProposalsIfAllMethodsAreAlreadyCalled() { var query = Fix.CreateDefaultQuery(); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Init()LVoid;")); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Execute()LVoid;")); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Finish()LVoid;")); var expected = new CoReProposal[] {}; var actual = _uut.Query(query); CollectionAssert.AreEquivalent(expected, actual); }
public void ShouldSetEvidenceOnDefinitionSite() { var query = Fix.CreateDefaultQuery(); query.definition = DefinitionSites.CreateDefinitionByReturn("LType.Create()LType;"); _uut.Query(query); var expected = SmilePBNRecommender.ConvertToLegalSmileName("RETURN:LType.Create()LType;"); var actual = _network.GetEvidenceId(Constants.DefinitionTitle); Assert.AreEqual(expected, actual); }
public void ShouldSetEvidenceOnMethodContext() { var query = Fix.CreateDefaultQuery(); query.methodCtx = new CoReMethodName("LType.M()LVoid;"); _uut.Query(query); var expected = SmilePBNRecommender.ConvertToLegalSmileName("LType.M()LVoid;"); var actual = _network.GetEvidenceId(Constants.MethodContextTitle); Assert.AreEqual(expected, actual); }
public void ShouldNotSetEvidencesOnNotMatchingQuery() { var query = Fix.CreateDefaultQuery(); query.definition = DefinitionSites.CreateDefinitionByReturn("LStrangeType.M()LType;"); query.sites.Add(CallSites.CreateReceiverCallSite("LStrangeType.M()LType;")); _uut.Query(query); var actual = _network.GetAllNodes().All(id => !_network.IsEvidence(id)); Assert.IsTrue(actual); }
public void ShouldProduceOrderedProposals() { var query = Fix.CreateDefaultQuery(); var expected = new[] { new CoReProposal(new CoReMethodName("LType.Execute()LVoid;"), 0.815), new CoReProposal(new CoReMethodName("LType.Finish()LVoid;"), 0.445), new CoReProposal(new CoReMethodName("LType.Init()LVoid;"), 0.37) }; var actual = _uut.Query(query); CollectionAssert.AreEquivalent(expected, actual); }
public void ShouldProduceAdaptedPropertiesIfCallSiteIsSet() { var query = Fix.CreateDefaultQuery(); query.sites.Add(CallSites.CreateReceiverCallSite("LType.Init()LVoid;")); var expected = new[] { new CoReProposal(new CoReMethodName("LType.Execute()LVoid;"), 0.682), new CoReProposal(new CoReMethodName("LType.Finish()LVoid;"), 0.164) }; var actual = _uut.Query(query); CollectionAssert.AreEquivalent(expected, actual); }
public void ShouldProduceAllProposalsIfNoMethodIsAlreadyCalled() { var query = Fix.CreateDefaultQuery(); var expected = new[] { new CoReMethodName("LType.Init()LVoid;"), new CoReMethodName("LType.Execute()LVoid;"), new CoReMethodName("LType.Finish()LVoid;") }; var proposals = _uut.Query(query); var actual = proposals.Select(p => p.Name); CollectionAssert.AreEquivalent(expected, actual); }
public void ShouldProduceAdaptedPropertiesIfContextsAreSet() { var query = Fix.CreateDefaultQuery(); query.classCtx = new CoReTypeName("LType"); query.methodCtx = new CoReMethodName("LType.M()LVoid;"); query.definition = DefinitionSites.CreateDefinitionByField("LType.object;LType"); var expected = new[] { new CoReProposal(new CoReMethodName("LType.Execute()LVoid;"), 0.803), new CoReProposal(new CoReMethodName("LType.Init()LVoid;"), 0.453), new CoReProposal(new CoReMethodName("LType.Finish()LVoid;"), 0.37) }; var actual = _uut.Query(query); CollectionAssert.AreEquivalent(expected, actual); }
public void SetUp() { _basePath = "some path -- the value irrelevant, it is only used for mocking"; _tmpPath = Path.Combine(Path.GetTempPath(), "Test_SmilePBNNetworkStoreTest_TmpPath"); var fullZipFileName = Path.Combine(_basePath, ZipFileForSomeType()); var fullXdslFileName = Path.Combine(_tmpPath, XdslFileForSomeType()); Directory.CreateDirectory(_tmpPath); File.WriteAllText(fullXdslFileName, Fix.CreateNetworkAsString()); _shouldZipBeFound = true; _shouldXdslBeFound = true; _io = Mock.Of <IIoUtils>(); Mock.Get(_io).Setup(io => io.DirectoryExists(_basePath)).Returns(true); Mock.Get(_io).Setup(io => io.FileExists(fullZipFileName)).Returns(() => _shouldZipBeFound); Mock.Get(_io).Setup(io => io.UnzipToTempFolder(fullZipFileName)).Returns(_tmpPath); Mock.Get(_io).Setup(io => io.FileExists(fullXdslFileName)).Returns(() => _shouldXdslBeFound); _sut = new SmilePBNRecommenderStore(_basePath, _io, new TypePathUtil()); }
public void SetUp() { _network = Fix.CreateNetwork(); _uut = new SmilePBNRecommender(Fix.SomeType(), _network); }