PlotDirector/PlotLine.Tests/WritingActivityTests.cs

22 lines
2.3 KiB
C#

using PlotLine.Models;
using PlotLine.Services.WritingActivity;
using PlotDirector.Companion.Protocol.Manuscript;
internal static class WritingActivityTests
{
public static void Run()
{
void Check(bool value,string message){if(!value)throw new Exception(message);Console.WriteLine("PASS writing activity "+message);}
ParagraphManuscript State(params (Guid Id,string Text)[] rows)=>new(){Paragraphs=rows.Select((r,i)=>new StoryParagraph{ChapterId=10,Occurrence=new ParagraphOccurrence{Id=r.Id,Ordinal=i,Text=r.Text}}).ToList()};
var id=Guid.NewGuid();var other=Guid.NewGuid();var before=State((id,"one two three\r"),(other,"four five\r"));
var baseline=WritingChangeCalculator.Compare(null,before);Check(baseline.AfterWords==5&&baseline.Added==0&&baseline.Removed==0,"baseline excludes pre-existing words");
var after=State((id,"one new three\r"),(other,"four five\r"));var c=WritingChangeCalculator.Compare(before,after);
Check(c.Added==1&&c.Removed==1&&c.Net==0,"zero-net replacement retains both sides");
c=WritingChangeCalculator.Compare(before,State((other,"four five\r"),(id,"one two three\r")));Check(c.Added==0&&c.Removed==0,"moving stable paragraphs has no word growth");
c=WritingChangeCalculator.Compare(before,State((id,"one\t two three\n"),(other,"four five\r")));Check(c.Net==0&&c.Added==0,"whitespace-only change has no word growth");
c=WritingChangeCalculator.Compare(before,State((other,"four five\r")));Check(c.Removed==3&&c.Added==0&&c.Scopes.Single().BeforeChapterID==10,"deletion preserves old paragraph scope");
c=WritingChangeCalculator.Compare(before,State((Guid.NewGuid(),"one two\r"),(Guid.NewGuid(),"three\r"),(other,"four five\r")));Check(c.Added==0&&c.Removed==0,"paragraph split does not invent growth");
c=WritingChangeCalculator.Compare(before,State((id,"one two three six seven\r"),(other,"four five\r")));Check(c.Added==2&&c.Net==c.AfterWords-c.BeforeWords,"gross and net reconcile");
c=WritingChangeCalculator.Compare(State((id,string.Join(' ',Enumerable.Repeat("a",2000)))),State((id,string.Join(' ',Enumerable.Repeat("b",2000)))));Check(c.Coverage.StartsWith("Partial")&&c.Added==2000&&c.Removed==2000,"large replacement explicitly qualifies token balance");
}
}