public void RemoveComponent_TheCurrentFolderDoesNotContainTheRemovableComponent_ReturnsFalse() { //Arrange Component removableFolder = SimpleComponentFactory.CreateComponent("Folder", "removableFolder"); //Act bool resultAfterRemoving = _currentFolder.Remove(removableFolder); //Assert Assert.False(resultAfterRemoving); }
public void CreateComponent_CreatingFolder_ReturnsNewObjectOfTypeFolder(string componentType) { //Arrange //Act Component resultAfterCreatingFolder1 = SimpleComponentFactory.CreateComponent(componentType, componentType); Component resultAfterCreatingFolder2 = SimpleComponentFactory.CreateComponent(componentType, componentType); //Assert Assert.AreEqual(resultAfterCreatingFolder1.GetType(), typeof(Folder)); Assert.AreEqual(resultAfterCreatingFolder2.GetType(), typeof(Folder)); }
public void CreateComponent_CreatingFile_ReturnsNewObjectOfTypeFile(string componentType) { //Arrange //Act Component resultAfterCreatingFile1 = SimpleComponentFactory.CreateComponent(componentType, componentType); Component resultAfterCreatingFile2 = SimpleComponentFactory.CreateComponent(componentType, componentType); //Assert Assert.AreEqual(typeof(File), resultAfterCreatingFile1.GetType()); Assert.AreEqual(typeof(File), resultAfterCreatingFile2.GetType()); }
public void CreateComponent_CreatingSomethingThatIsNotAComponent_ReturnsNull(string componentType) { //Arrange //Act Component resultAfterCreatingFolder = SimpleComponentFactory.CreateComponent(componentType, "Folder"); Component resultAfterCreatingFile = SimpleComponentFactory.CreateComponent(componentType, "File"); //Assert Assert.AreEqual(null, resultAfterCreatingFolder); Assert.AreEqual(null, resultAfterCreatingFile); }
public void AddNewFile_ThereIsAlreadyAComponentWithTheSameName_GiveAnErrorMessage() { //Arrange Component fileWithTheSameName = SimpleComponentFactory.CreateComponent("File", "SameName"); //Act _consoleFileManager.AddNewFileToTheCurrentDirectory(fileWithTheSameName.Name); //Assert string expectedMessage = "A component with this name already exists"; string actualMessage = _lastMessageFromViewer; Assert.AreEqual(expectedMessage, actualMessage); }
public void RemoveComponent_AnyAttemptToRemoveAComponentFromFile_ReturnsFalse() { //Arrange Component removableFolder = SimpleComponentFactory.CreateComponent("Folder", "removableFolder"); Component removableFile = SimpleComponentFactory.CreateComponent("File", "removableFile"); //Act bool resultAfterRemovingFolder = _currentFile.Remove(removableFolder); bool resultAfterRemovingFile = _currentFile.Remove(removableFile); //Assert Assert.False(resultAfterRemovingFolder); Assert.False(resultAfterRemovingFile); }
public void AddNewComponent_AnyAttemptToAddAComponentInFile_ReturnsFalse() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); Component newFile = SimpleComponentFactory.CreateComponent("File", "newFile"); //Act bool resultAfterAddingFolder = _currentFile.Add(newFolder); bool resultAfterAddingFile = _currentFile.Add(newFile); //Assert Assert.False(resultAfterAddingFolder); Assert.False(resultAfterAddingFile); }
public void RemoveComponent_TheCurrentFolderContainsTheRemovableComponent_RemovingComponentAndReturnsTrue() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); _currentFolder.Add(newFolder); //Act bool resultAfterRemoving = _currentFolder.Remove(newFolder); //Assert bool IsTheRemovedComponentAppearInTheCurrentFolder = isThereComponent("newFolder"); Assert.False(IsTheRemovedComponentAppearInTheCurrentFolder); Assert.True(resultAfterRemoving); }
public void GetPathOfTheCurrentDirectory_AddNewFolderAfterRootAndGoDownThere_ReturnPathWithNewFolderAfterRoot() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); Component rootFolder = _currentDirectory.GetCurrentComponent(); rootFolder.Add(newFolder); _currentDirectory.Down("newFolder"); //Act string actualPathOfCurrentDirectory = _currentDirectory.GetPathOfTheCurrentDirectory(); //Assert string expectedPathOfCurrentDirectory = "Root/newFolder/"; Assert.AreEqual(actualPathOfCurrentDirectory, expectedPathOfCurrentDirectory); }
public void GetPathOfTheCurrentDirectory_WeAreNotInTheRoot_ReturnTheFullPath(string nameOfFolderOnTheLowerLevel) { //Arrange Component componentOnTheLowerLevel = SimpleComponentFactory.CreateComponent("Folder", nameOfFolderOnTheLowerLevel); _currentDirectory.GetCurrentComponent().Add(componentOnTheLowerLevel); _currentDirectory.Down(nameOfFolderOnTheLowerLevel); //Act string actualPathOfCurrentDirectory = _currentDirectory.GetPathOfTheCurrentDirectory(); //Assert string expectedPathOfCurrentDirectory = $"Root/{nameOfFolderOnTheLowerLevel}/"; Assert.AreEqual(actualPathOfCurrentDirectory, expectedPathOfCurrentDirectory); }
public void GetCurrentComponent_AddNewFolderAfterRootAndGoDownThere_ReturnNameOfNewAddedFolder() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); Component rootFolder = _currentDirectory.GetCurrentComponent(); rootFolder.Add(newFolder); _currentDirectory.Down("newFolder"); //Act string actualNameOfCurrentComponent = _currentDirectory.GetCurrentComponent().Name; //Assert string expectedNameOfCurrentComponent = "newFolder"; Assert.AreEqual(actualNameOfCurrentComponent, expectedNameOfCurrentComponent); }
public void GetContents_FromNotEmptyFolder_ReturnsContentsOfThisFolder() { //Arrange Component folder = SimpleComponentFactory.CreateComponent("Folder", "folder"); Component file = SimpleComponentFactory.CreateComponent("File", "file"); _currentFolder.Add(folder); _currentFolder.Add(file); //Act List <Component> resultAfterGettingContentsFromNotEmptyFolder = _currentFolder.GetContents(); //Assert Assert.NotNull(resultAfterGettingContentsFromNotEmptyFolder); Assert.True(resultAfterGettingContentsFromNotEmptyFolder.Any(f => f.Name == "folder")); Assert.True(resultAfterGettingContentsFromNotEmptyFolder.Any(f => f.Name == "file")); }
public void GoDown_ComponentInWhichWeWantToGoDownIsComposite_GoDownIntoAComponentAndReturnsTrue() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "lowerFolder"); Component rootFolder = _currentDirectory.GetCurrentComponent(); rootFolder.Add(newFolder); //Act bool resultOfGoDown = _currentDirectory.Down("lowerFolder"); //Assert string expectedNameOfCurrentComponent = "lowerFolder"; string actualNameOfCurrentComponent = _currentDirectory.GetCurrentComponent().Name; Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent); Assert.True(resultOfGoDown); }
public void GoDown_ComponentInWhichWeWantToGoDownIsNotComposite_NotGoDownAndReturnsFalse() { //Arrange Component newFile = SimpleComponentFactory.CreateComponent("File", "lowerFile"); Component rootFolder = _currentDirectory.GetCurrentComponent(); rootFolder.Add(newFile); //Act bool resultOfGoDown = _currentDirectory.Down("lowerFile"); //Assert string expectedNameOfCurrentComponent = "Root"; string actualNameOfCurrentComponent = _currentDirectory.GetCurrentComponent().Name; Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent); Assert.False(resultOfGoDown); }
public void RiseUp_WeAreNotInTheRoot_RiseUpAndReturnsTrue() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "lowerFolder"); Component rootFolder = _currentDirectory.GetCurrentComponent(); rootFolder.Add(newFolder); _currentDirectory.Down("lowerFolder"); //Act bool resultOfRiseUp = _currentDirectory.Up(); //Assert string expectedNameOfCurrentComponent = "Root"; string actualNameOfCurrentComponent = _currentDirectory.GetCurrentComponent().Name; Assert.AreEqual(expectedNameOfCurrentComponent, actualNameOfCurrentComponent); Assert.True(resultOfRiseUp); }
public void GoDownToTheLowerLevel_ComponentExistButIsNotAComposite_GiveAnErrorMessage() { //Arrange List <Component> fakeListWithNonCompositeComponent = new List <Component>(); fakeListWithNonCompositeComponent.Add(SimpleComponentFactory.CreateComponent("File", "nameOfNonCompositeComponent")); FakeComponent.Setup(method => method.GetContents()) .Returns(fakeListWithNonCompositeComponent); //Act _consoleFileManager.GoDownToTheLowerLevel("nameOfNonCompositeComponent"); //Assert string expectedMessage = "The component nameOfNonCompositeComponent can not be descended because it is not a composite"; string actualMessage = _lastMessageFromViewer; Assert.AreEqual(expectedMessage, actualMessage); }
public void AddNewComponent_ThereIsNotComponentWithTheSameName_AddingANewComponentAndReturnsTrue() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); Component newFile = SimpleComponentFactory.CreateComponent("File", "newFile"); //Act bool resultAfterAddingFolder = _currentFolder.Add(newFolder); bool resultAfterAddingFile = _currentFolder.Add(newFile); //Assert bool IsTheAddedFolderAppearInTheCurrentFolder = isThereComponent("newFolder"); bool IsTheAddedFileAppearInTheCurrentFolder = isThereComponent("newFile"); Assert.True(IsTheAddedFolderAppearInTheCurrentFolder); Assert.True(IsTheAddedFileAppearInTheCurrentFolder); Assert.True(resultAfterAddingFolder); Assert.True(resultAfterAddingFile); }
public void AddNewComponent_ThereIsAComponentWithTheSameName_NotAddingANewComponentAndReturnsFalse() { //Arrange Component newFolder = SimpleComponentFactory.CreateComponent("Folder", "newFolder"); Component fileWithTheSameName = SimpleComponentFactory.CreateComponent("File", "newFolder"); _currentFolder.Add(newFolder); //Act bool resultAfterAddingFolderWithTheSameName = _currentFolder.Add(newFolder); bool resultAfterAddingFileWithTheSameName = _currentFolder.Add(fileWithTheSameName); //Assert int countOfComponentsInCurrentFolderAfterAdding = _currentFolder.GetContents().Count; int actualNumberOfComponentsInCurrentFolderAfterAdding = 1; Assert.AreEqual(countOfComponentsInCurrentFolderAfterAdding, actualNumberOfComponentsInCurrentFolderAfterAdding); Assert.False(resultAfterAddingFolderWithTheSameName); Assert.False(resultAfterAddingFileWithTheSameName); }
public FolderTests() { _currentFolder = SimpleComponentFactory.CreateComponent("Folder", "TestFolder"); }
public static IDataTransform Create(IHostEnvironment env, Arguments args, IDataView input) { Contracts.CheckValue(env, nameof(env)); var host = env.Register("Tree Featurizer Transform"); host.CheckValue(args, nameof(args)); host.CheckValue(input, nameof(input)); host.CheckUserArg(!string.IsNullOrWhiteSpace(args.TrainedModelFile) || args.Trainer.IsGood(), nameof(args.TrainedModelFile), "Please specify either a trainer or an input model file."); host.CheckUserArg(!string.IsNullOrEmpty(args.FeatureColumn), nameof(args.FeatureColumn), "Transform needs an input features column"); IDataTransform xf; using (var ch = host.Start("Create Tree Ensemble Scorer")) { var scorerArgs = new TreeEnsembleFeaturizerBindableMapper.Arguments() { Suffix = args.Suffix }; if (!string.IsNullOrWhiteSpace(args.TrainedModelFile)) { if (args.Trainer.IsGood()) { ch.Warning("Both an input model and a trainer were specified. Using the model file."); } ch.Trace("Loading model"); IPredictor predictor; using (Stream strm = new FileStream(args.TrainedModelFile, FileMode.Open, FileAccess.Read)) using (var rep = RepositoryReader.Open(strm, ch)) ModelLoadContext.LoadModel <IPredictor, SignatureLoadModel>(host, out predictor, rep, ModelFileUtils.DirPredictor); ch.Trace("Creating scorer"); var data = TrainAndScoreTransform.CreateDataFromArgs(ch, input, args); // Make sure that the given predictor has the correct number of input features. if (predictor is CalibratedPredictorBase) { predictor = ((CalibratedPredictorBase)predictor).SubPredictor; } // Predictor should be a FastTreePredictionWrapper, which implements IValueMapper, so this should // be non-null. var vm = predictor as IValueMapper; ch.CheckUserArg(vm != null, nameof(args.TrainedModelFile), "Predictor in model file does not have compatible type"); if (vm.InputType.VectorSize != data.Schema.Feature.Type.VectorSize) { throw ch.ExceptUserArg(nameof(args.TrainedModelFile), "Predictor in model file expects {0} features, but data has {1} features", vm.InputType.VectorSize, data.Schema.Feature.Type.VectorSize); } var bindable = new TreeEnsembleFeaturizerBindableMapper(env, scorerArgs, predictor); var bound = bindable.Bind(env, data.Schema); xf = new GenericScorer(env, scorerArgs, input, bound, data.Schema); } else { ch.Assert(args.Trainer.IsGood()); ch.Trace("Creating TrainAndScoreTransform"); var trainScoreArgs = new TrainAndScoreTransform.Arguments(); args.CopyTo(trainScoreArgs); trainScoreArgs.Trainer = new SubComponent <ITrainer, SignatureTrainer>(args.Trainer.Kind, args.Trainer.Settings); trainScoreArgs.Scorer = new SimpleComponentFactory <IDataView, ISchemaBoundMapper, RoleMappedSchema, IDataScorerTransform>( (e, data, mapper, trainSchema) => Create(e, scorerArgs, data, mapper, trainSchema)); var mapperFactory = new SimpleComponentFactory <IPredictor, ISchemaBindableMapper>( (e, predictor) => new TreeEnsembleFeaturizerBindableMapper(e, scorerArgs, predictor)); var labelInput = AppendLabelTransform(host, ch, input, trainScoreArgs.LabelColumn, args.LabelPermutationSeed); var scoreXf = TrainAndScoreTransform.Create(host, trainScoreArgs, labelInput, mapperFactory); if (input == labelInput) { return(scoreXf); } return((IDataTransform)ApplyTransformUtils.ApplyAllTransformsToData(host, scoreXf, input, labelInput)); } ch.Done(); } return(xf); }
public FileTests() { _currentFile = SimpleComponentFactory.CreateComponent("File", "TestFile"); }
public void SetUp() { _currentFolder = SimpleComponentFactory.CreateComponent("Folder", "TestFolder"); }