Beispiel #1
0
        public void EmptyArray_ShouldReturnZeroWords()
        {
            var wordsFilter = new WordsFilter(CreateWordsLoaderStub(val => ""));
            var words = wordsFilter.Filter();

            Assert.Equal(0, words.Count);
        }
Beispiel #2
0
        public void OneTimeSetup()
        {
            var dictionaryAff = Path.GetFullPath("../../../dictionaries/en.aff");
            var dictionaryDic = Path.GetFullPath("../../../dictionaries/en.dic");

            WordsFilter = new WordsFilter(new Hunspell(dictionaryAff, dictionaryDic)).RemovePrepositions().Normalize();
        }
Beispiel #3
0
        private static Bitmap Visualize(CloudOptions cloudOptions)
        {
            var width  = cloudOptions.Width == 0 ? Screen.PrimaryScreen.Bounds.Width : cloudOptions.Width;
            var height = cloudOptions.Height == 0 ? Screen.PrimaryScreen.Bounds.Height : cloudOptions.Height;

            var cloudDesign = new SimpleCloudDesign(
                Color.FromName(cloudOptions.BackgroundColor),
                cloudOptions.Font,
                new SolidBrush(Color.FromName(cloudOptions.FontColor)),
                new Rectangle(0, 0, width, height));

            var builder = new ContainerBuilder();

            builder.Register(c => cloudDesign).As <ICloudDesign>();
            var shape = new SpiralCloudShape(cloudDesign, cloudOptions.Spreading);

            builder.Register(s => shape).As <ICloudShape>();
            builder.RegisterType <CircularCloudLayouter>().As <IRectangleLayouter>();
            builder.RegisterType <TxtTagReader>().As <ITagsReader>();
            builder.RegisterType <TagsUnifier>().As <ITagsHandler>();
            if (cloudOptions.ForbiddenWords != null)
            {
                var filter = new WordsFilter(ReadStringsFromTxt(cloudOptions.ForbiddenWords));
                builder.Register(f => filter).As <ITagsHandler>();
            }
            builder.RegisterType <TagsCloudVisualizator>();

            var container = builder.Build();

            var vizualizator = container.Resolve <TagsCloudVisualizator>();

            return(vizualizator.Visualize(cloudOptions.TagsFile));
        }
Beispiel #4
0
        public void NoWordFound_ShouldReturnZeroWords()
        {
            var wordsFilter = new WordsFilter(CreateWordsLoaderStub(val => "al, bums"));
            var words = wordsFilter.Filter();

            Assert.Equal(0, words.Count);
        }
 public void SetUp()
 {
     spiral                   = new ArchimedeanSpiral(new Point(0, 0));
     wordsProvider            = new CircularWordsProvider();
     wordsFilter              = new WordsFilter().Normalize();
     tagCloudWithCenterInZero =
         new CircularCloudLayouter(spiral, wordsProvider, wordsFilter);
 }
Beispiel #6
0
        public void WordFoundWithStartPosition_ShouldReturnOneWords()
        {
            var wordsFilter = new WordsFilter(CreateWordsLoaderStub(val => "al, bums, albums"));
            var words = wordsFilter.Filter();

            Assert.Equal(1, words.Count);
            Assert.Equal("albums", words[0]);
        }
Beispiel #7
0
        public void ExcludeIncorrectWord()
        {
            var analyzer = new Mock <IWordAnalyzer>();

            analyzer.Setup((a) => a.IsCorrectWord("слово")).Returns(false);
            var filter = new WordsFilter(analyzer.Object, _converter.Object);

            filter.FilterWords(_reader.Object).Should().BeEmpty();
        }
Beispiel #8
0
 public void SetUp()
 {
     
     var bannedLines = new []
     {
         "I have some",
         "Should be"
     };
     wordsFilter =
         new WordsFilter(bannedLines);
 }
Beispiel #9
0
        public void Reader_ShouldBePerformedOnce()
        {
            var calls  = 0;
            var reader = new Mock <IWordReader>();

            reader.Setup((r) => r.ReadWords()).Returns(_words)
            .Callback(() => calls++);
            var filter = new WordsFilter(_analyzer.Object, _converter.Object);

            filter.FilterWords(reader.Object);
            calls.Should().Be(1);
        }
Beispiel #10
0
        public void ChangeWords()
        {
            var converter = new Mock <IWordConverter>();

            converter.Setup((c) => c.ConvertWord(It.IsAny <string>())).Returns((string s) => s + "!");
            var filter = new WordsFilter(_analyzer.Object, converter.Object);

            filter.FilterWords(_reader.Object).ShouldBeEquivalentTo(new List <string>()
            {
                "слово!"
            });
        }
Beispiel #11
0
        public void ExcludeWords_WhenBoringWords()
        {
            var words = new List <string>()
            {
                "и"
            };
            var reader = new Mock <IWordReader>();

            reader.Setup((r) => r.ReadWords()).Returns(words);
            var filter = new WordsFilter(new BoringWordsAnalyzer(), _converter.Object);

            filter.FilterWords(reader.Object).Should().BeEmpty();
        }
Beispiel #12
0
        public async Task CreateComment(string content, int episodeId, string userId)
        {
            Comment comment = new Comment()
            {
                UserId         = userId,
                EpisodeId      = episodeId,
                CommentContent = WordsFilter.CensorComment(content),
                DateCreatedAt  = DateTime.Now
            };

            await this.AnimeContext.Comments.AddAsync(comment);

            await this.AnimeContext.SaveChangesAsync();
        }
Beispiel #13
0
        public void MultipleWords_ShouldReturnAnArray()
        {
            var wordsFilter =
                new WordsFilter(
                    CreateWordsLoaderStub(
                        var =>
                            "al, albums, aver, bar, barely, be, befoul, bums, by, cat, con, convex, ely, foul, here, hereby, jig, jigsaw, or, saw, tail, tailor, vex, we, weaver"));
            var words = wordsFilter.Filter();

            Assert.Equal(8, words.Count);
            Assert.Contains("albums", words);
            Assert.Contains("barely", words);
            Assert.Contains("befoul", words);
            Assert.Contains("convex", words);
            Assert.Contains("hereby", words);
            Assert.Contains("jigsaw", words);
            Assert.Contains("tailor", words);
            Assert.Contains("weaver", words);
        }
Beispiel #14
0
        public void Analyzer_ShouldCheckEachWords()
        {
            var words = new List <string>()
            {
                "первое", "второе"
            };
            var reader = new Mock <IWordReader>();

            reader.Setup((r) => r.ReadWords()).Returns(words);
            var analyzer = new Mock <IWordAnalyzer>();
            var calls    = 0;

            analyzer.Setup((a) => a.IsCorrectWord(It.IsAny <string>()))
            .Returns(true)
            .Callback(() => calls++);
            var filter = new WordsFilter(analyzer.Object, _converter.Object);

            filter.FilterWords(reader.Object).ToList();
            calls.Should().Be(words.Count);
        }
Beispiel #15
0
        private static void RunPart2()
        {
            string fileLocation = GetFileLocation("part2fileinput.txt");

            var fileLoader = new FileWordsLoader(fileLocation);
            var wordsFilter = new WordsFilter(fileLoader);
            List<string> filteredWords = null;
            try
            {
                filteredWords = wordsFilter.Filter();
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File was not found at location: {0}", fileLocation);
            }

            foreach (var word in filteredWords)
            {
                Console.WriteLine(word);
            }
        }
Beispiel #16
0
        public void ReturnInLowerCase_WhenWordConverter()
        {
            var filter = new WordsFilter(_analyzer.Object, new WordConverter());

            filter.FilterWords(_reader.Object).ShouldBeEquivalentTo(_words.Select(w => w.ToLower()));
        }
Beispiel #17
0
        public void ReturnSameWords_WhenAnalyzerAndConverterDoingNothing()
        {
            var filter = new WordsFilter(_analyzer.Object, _converter.Object);

            filter.FilterWords(_reader.Object).ShouldBeEquivalentTo(_words);
        }