Segment() public method

public Segment ( Variety variety ) : void
variety SIL.Cog.Domain.Variety
return void
コード例 #1
0
ファイル: SegmentsViewModelTests.cs プロジェクト: rmunn/cog
        public void Segments()
        {
            DispatcherHelper.Initialize();
            var segmentPool = new SegmentPool();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService = Substitute.For<IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);
            project.Meanings.AddRange(new[] {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")});
            project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
            project.Varieties[0].Words.AddRange(new[] {new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2])});
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"b", "f", "l", "g", "h"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Labial", "Coronal", "Dorsal", "Guttural"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[2]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[3]}));
            Assert.That(segments.Categories[3].Segments, Is.EquivalentTo(new[] {segments.Segments[4]}));

            project.Varieties[0].Words.RemoveAll(project.Meanings[0]);
            analysisService.Segment(project.Varieties[0]);
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"b", "f", "g", "h"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Labial", "Dorsal", "Guttural"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[2]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[3]}));

            segments.SyllablePosition = SyllablePosition.Nucleus;
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] {"i", "u", "ʊ", "ɛ", "ə", "æ"}));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] {"Close", "Mid", "Open"}));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] {segments.Segments[0], segments.Segments[1], segments.Segments[2]}));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] {segments.Segments[3], segments.Segments[4]}));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] {segments.Segments[5]}));

            foreach (Variety variety in project.Varieties)
                variety.Words.Clear();
            analysisService.SegmentAll();
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.False);
            Assert.That(segments.Segments, Is.Empty);
            Assert.That(segments.Categories, Is.Empty);
        }