Added the value card sort to the BeyondFacts Lab (#1206)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-15 13:06:06 +01:00
1 parent 1361b984eb
commit 3ca4b3878b
42 files changed
+2111 -114

No files matched your search

@@ -343,6 +343,68 @@ public sealed class BeyondFactsLabStoreTests
}
}
[Test]
public async Task ACardSortIsStoredWithTheFormOfItsStep()
{
var store = this.CreateStore();
var created = await store.CreateAsync("Panel");
var form = new BflStepFormData { CardSort = new() };
form.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
var ownValue = form.CardSort.AddOwnValue("Neugier", "Fragen stellen")!;
form.CardSort.ChooseFocus(["honesty", ownValue.Id]);
await store.SaveFormAsync(created.ProjectId, BflStep.VALUES_AND_PERSPECTIVES, form);
var loaded = (await this.CreateStore().LoadFormAsync(created.ProjectId, BflStep.VALUES_AND_PERSPECTIVES)).CardSort;
using (Assert.EnterMultipleScope())
{
Assert.That(loaded, Is.Not.Null);
Assert.That(loaded!.CategoryOf("honesty"), Is.EqualTo(BflValueCategory.ESPECIALLY_IMPORTANT));
Assert.That(loaded.OwnValues.Select(value => (value.Id, value.Name, value.Definition)), Is.EqualTo(new[] { (ownValue.Id, "Neugier", "Fragen stellen") }));
Assert.That(loaded.Focus, Is.EqualTo(new[] { "honesty", ownValue.Id }));
}
}
[Test]
public async Task AFormWithoutACardSortStoresNone()
{
var store = this.CreateStore();
var created = await store.CreateAsync("Panel");
var form = new BflStepFormData();
form.Set(BflFieldCatalog.CORE_THESES, "Thesis");
await store.SaveFormAsync(created.ProjectId, BflStep.KNOWLEDGE, form);
var json = await File.ReadAllTextAsync(Path.Combine(this.RootDirectory, created.ProjectId.ToString("D"), "steps", "02-knowledge", "form.json"));
Assert.That(json, Does.Not.Contain("cardSort"));
}
[Test]
public async Task AFormOfTheFirstVersionIsStillOpened()
{
var store = this.CreateStore();
var created = await store.CreateAsync("Panel");
await this.WriteFormFileAsync(created.ProjectId, "04-values", """{ "schemaVersion": 1, "values": { "values_and_concerns": "Text" } }""");
var form = await store.LoadFormAsync(created.ProjectId, BflStep.VALUES_AND_PERSPECTIVES);
using (Assert.EnterMultipleScope())
{
Assert.That(form.Get(BflFieldCatalog.VALUES_AND_CONCERNS), Is.EqualTo("Text"));
Assert.That(form.CardSort, Is.Null);
}
}
[Test]
public async Task AFormWithABrokenCardSortIsNotOpened()
{
var store = this.CreateStore();
var created = await store.CreateAsync("Panel");
await this.WriteFormFileAsync(created.ProjectId, "04-values", """{ "schemaVersion": 2, "values": {}, "cardSort": { "categories": {}, "ownValues": [ null ], "focus": [] } }""");
await Assert.ThrowsAsync<InvalidDataException>(async () => await store.LoadFormAsync(created.ProjectId, BflStep.VALUES_AND_PERSPECTIVES));
}
[Test]
public async Task AStepWithoutAFormGetsAnEmptyOne()
{
@@ -401,7 +463,7 @@ public sealed class BeyondFactsLabStoreTests
[Test]
public async Task AFormOfANewerVersionIsNotOverwritten()
{
const string NEWER = """{ "schemaVersion": 2, "values": {} }""";
const string NEWER = """{ "schemaVersion": 3, "values": {} }""";
var store = this.CreateStore();
var created = await store.CreateAsync("Panel");
var formPath = await this.WriteFormFileAsync(created.ProjectId, "05-strategy", NEWER);
@@ -0,0 +1,152 @@
using System.Globalization;
using AIStudio.Assistants.BeyondFactsLab;
using AIStudio.Settings.DataModel;
namespace AIStudio.Tests.BeyondFactsLab;
/// <summary>
/// Checks how the card sort of the BeyondFacts Lab reaches the chat of its step: as part of the details, with every
/// value of the deck, and never in the chats of the other steps.
/// </summary>
[TestFixture]
public sealed class BflCardSortPromptTests
{
private const string CORE = "{{DETAILS}}";
private static readonly BflPromptParts PARTS = new(CORE, "Leitfaden", "Schritt", "Anrede", string.Empty);
[Test]
public async Task TheCardSortReachesOnlyTheChatOfItsOwnStep()
{
var deck = await EnglishDeckAsync();
var values = new BflStepFormData { CardSort = new() };
values.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
values.Set(BflFieldCatalog.VALUES_AND_CONCERNS, "Offenheit");
var forms = new Dictionary<BflStep, BflStepFormData> { [BflStep.VALUES_AND_PERSPECTIVES] = values };
foreach (var step in BflStep.All)
{
var prompt = BflPromptComposer.Compose(PARTS, step, forms, [], "Deutsch", valueDeck: deck);
using (Assert.EnterMultipleScope())
{
Assert.That(prompt.Contains("Werte-Sortierung", StringComparison.Ordinal), Is.EqualTo(step is BflStep.VALUES_AND_PERSPECTIVES), step.ToString());
Assert.That(prompt, Does.Contain("Offenheit"), "The other details of the step reach every chat, as before.");
}
}
}
[Test]
public async Task TheChatSeesEveryValueWithItsCategoryAndTheSource()
{
var deck = await EnglishDeckAsync();
var values = new BflStepFormData { CardSort = new() };
values.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
values.CardSort.Sort("progress", BflValueCategory.LESS_IMPORTANT);
var prompt = Compose(values, deck);
using (Assert.EnterMultipleScope())
{
Assert.That(prompt, Does.Contain("- Werte-Sortierung nach Miller, W. R., C’de Baca, J., Matthews, D. B., & Wilbourne, P. L. (2001). Personal Values Card Sort. University of New Mexico:"));
Assert.That(prompt, Does.Contain("\n - Runde 1:\n - Honesty (Present statements sincerely): Especially important\n"));
Assert.That(prompt, Does.Contain($" - Safety (Avoid harm): {BflValueCategory.NONE.Title}\n"));
Assert.That(prompt, Does.Contain($" - Progress (Develop new things and make improvements possible): {BflValueCategory.LESS_IMPORTANT.Title}\n"));
Assert.That(prompt, Does.Contain("\n - Runde 3:"));
foreach (var card in deck.Cards)
Assert.That(prompt, Does.Contain($" - {card.Name} ({card.Definition}): "), card.Id);
}
}
[Test]
public async Task TheChatSeesTheOwnValuesAndTheValuesToLookAtMoreClosely()
{
var deck = await EnglishDeckAsync();
var values = new BflStepFormData { CardSort = new() };
var curiosity = values.CardSort.AddOwnValue("Curiosity", "Ask questions")!;
values.CardSort.AddOwnValue("Patience", string.Empty);
values.CardSort.ChooseFocus(["honesty", curiosity.Id]);
var prompt = Compose(values, deck);
using (Assert.EnterMultipleScope())
{
Assert.That(prompt, Does.Contain(" - Eigene Werte der Person:\n - Curiosity (Ask questions)\n - Patience (ohne Erläuterung)\n"));
Assert.That(prompt, Does.Contain(" - Genauer betrachten möchte die Person: Honesty, Curiosity"));
}
}
[Test]
public async Task WithoutAnySortingTheChatStillSeesTheDeckToOfferIt()
{
var deck = await EnglishDeckAsync();
var prompt = Compose(new BflStepFormData(), deck);
using (Assert.EnterMultipleScope())
{
Assert.That(prompt, Does.Contain($" - Honesty (Present statements sincerely): {BflValueCategory.NONE.Title}"));
Assert.That(prompt, Does.Contain(" - Eigene Werte der Person: keine"));
Assert.That(prompt, Does.Contain(" - Genauer betrachten möchte die Person: noch keine Auswahl"));
}
}
[Test]
public async Task AValueTheDeckDoesNotKnowStaysOut()
{
var deck = await EnglishDeckAsync();
var values = new BflStepFormData { CardSort = new() { Focus = ["value_of_another_deck"] } };
values.CardSort.Sort("value_of_another_deck", BflValueCategory.ESPECIALLY_IMPORTANT);
var prompt = Compose(values, deck);
using (Assert.EnterMultipleScope())
{
Assert.That(prompt, Does.Not.Contain("value_of_another_deck"));
Assert.That(prompt, Does.Contain("noch keine Auswahl"));
}
}
[Test]
public void WithoutADeckThePromptLeavesTheCardSortOut()
{
var values = new BflStepFormData { CardSort = new() };
values.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
var prompt = BflPromptComposer.Compose(PARTS, BflStep.VALUES_AND_PERSPECTIVES, new Dictionary<BflStep, BflStepFormData> { [BflStep.VALUES_AND_PERSPECTIVES] = values }, [], "Deutsch");
Assert.That(prompt, Does.Not.Contain("Werte-Sortierung"));
}
[Test]
public async Task ThePromptOfTheStepLeavesTheValuesToTheDeck()
{
var step = await BflPromptLibrary.ReadBuiltInAsync(BflPromptLibrary.StepPath(BflStep.VALUES_AND_PERSPECTIVES));
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("de"));
using (Assert.EnterMultipleScope())
{
foreach (var card in deck.Cards)
Assert.That(step, Does.Not.Contain(card.Definition).IgnoreCase, $"The prompt of the step repeats the value '{card.Id}' of the deck.");
Assert.That(step, Does.Contain("Werte-Sortierung"));
}
}
[Test]
public async Task TheRealPromptOfTheStepCarriesTheCardSort()
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("de"));
var parts = await BflPromptLibrary.LoadPartsAsync(BflStep.VALUES_AND_PERSPECTIVES, AddressForm.FORMAL);
var values = new BflStepFormData { CardSort = new() };
values.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
var prompt = BflPromptComposer.Compose(parts, BflStep.VALUES_AND_PERSPECTIVES, new Dictionary<BflStep, BflStepFormData> { [BflStep.VALUES_AND_PERSPECTIVES] = values }, [], "Deutsch", valueDeck: deck);
Assert.That(prompt, Does.Contain(" - Ehrlichkeit (Aussagen aufrichtig darstellen): "));
}
private static string Compose(BflStepFormData values, BflValueDeck deck) => BflPromptComposer.Compose(PARTS, BflStep.VALUES_AND_PERSPECTIVES, new Dictionary<BflStep, BflStepFormData> { [BflStep.VALUES_AND_PERSPECTIVES] = values }, [], "Deutsch", valueDeck: deck);
private static Task<BflValueDeck> EnglishDeckAsync() => BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
}
@@ -0,0 +1,172 @@
using System.Globalization;
using AIStudio.Assistants.BeyondFactsLab;
namespace AIStudio.Tests.BeyondFactsLab;
/// <summary>
/// Checks the card sort of the BeyondFacts Lab: values stay open until the person sorts them, values of their own keep
/// their limits, and at most three values get looked at more closely.
/// </summary>
[TestFixture]
public sealed class BflCardSortTests
{
[Test]
public void AValueStaysOpenUntilThePersonSortsIt()
{
var cardSort = new BflCardSort();
using (Assert.EnterMultipleScope())
{
Assert.That(cardSort.CategoryOf("honesty"), Is.EqualTo(BflValueCategory.NONE));
Assert.That(cardSort.IsEmpty, Is.True);
}
}
[Test]
public void ASortedValueCanBeOpenedAgain()
{
var cardSort = new BflCardSort();
cardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
cardSort.Sort("honesty", BflValueCategory.UNCLEAR);
var changed = cardSort.CategoryOf("honesty");
cardSort.Sort("honesty", BflValueCategory.NONE);
using (Assert.EnterMultipleScope())
{
Assert.That(changed, Is.EqualTo(BflValueCategory.UNCLEAR));
Assert.That(cardSort.Categories, Is.Empty);
Assert.That(cardSort.IsEmpty, Is.True);
}
}
[Test]
public void TheButtonsOfferEveryCategoryButNone()
{
Assert.That(BflValueCategory.All, Is.EquivalentTo(Enum.GetValues<BflValueCategory>().Where(category => category is not BflValueCategory.NONE)));
}
[Test]
public void AnOwnValueNeedsAName()
{
var cardSort = new BflCardSort();
using (Assert.EnterMultipleScope())
{
Assert.That(cardSort.AddOwnValue(" ", "Meaning"), Is.Null);
Assert.That(cardSort.OwnValues, Is.Empty);
}
}
[Test]
public void AnOwnValueIsTrimmedAndCut()
{
var cardSort = new BflCardSort();
var value = cardSort.AddOwnValue($" {new string('n', BflCardSort.MAX_NAME_LENGTH + 5)} ", new string('d', BflCardSort.MAX_DEFINITION_LENGTH + 5));
using (Assert.EnterMultipleScope())
{
Assert.That(value!.Name, Has.Length.EqualTo(BflCardSort.MAX_NAME_LENGTH));
Assert.That(value.Definition, Has.Length.EqualTo(BflCardSort.MAX_DEFINITION_LENGTH));
Assert.That(value.Id, Is.Not.Empty);
Assert.That(cardSort.IsEmpty, Is.False);
}
}
[Test]
public void APersonAddsAtMostTenValuesOfTheirOwn()
{
var cardSort = new BflCardSort();
for (var index = 0; index < BflCardSort.MAX_OWN_VALUES; index++)
cardSort.AddOwnValue($"Value {index}", string.Empty);
using (Assert.EnterMultipleScope())
{
Assert.That(cardSort.CanAddOwnValue, Is.False);
Assert.That(cardSort.AddOwnValue("One more", string.Empty), Is.Null);
Assert.That(cardSort.OwnValues, Has.Count.EqualTo(BflCardSort.MAX_OWN_VALUES));
}
}
[Test]
public void AnOwnValueKeepsItsNameWhenTheNewOneIsEmpty()
{
var cardSort = new BflCardSort();
var value = cardSort.AddOwnValue("Curiosity", "Ask questions")!;
var emptied = cardSort.ChangeOwnValue(value.Id, " ", "Something else");
var changed = cardSort.ChangeOwnValue(value.Id, "Courage", " Speak up ");
using (Assert.EnterMultipleScope())
{
Assert.That(emptied, Is.False);
Assert.That(changed, Is.True);
Assert.That(value.Name, Is.EqualTo("Courage"));
Assert.That(value.Definition, Is.EqualTo("Speak up"));
Assert.That(cardSort.ChangeOwnValue("unknown", "Name", string.Empty), Is.False);
}
}
[Test]
public void ARemovedOwnValueLeavesTheValuesToLookAtMoreClosely()
{
var cardSort = new BflCardSort();
var value = cardSort.AddOwnValue("Curiosity", string.Empty)!;
cardSort.ChooseFocus(["honesty", value.Id]);
cardSort.RemoveOwnValue(value.Id);
using (Assert.EnterMultipleScope())
{
Assert.That(cardSort.OwnValues, Is.Empty);
Assert.That(cardSort.Focus, Is.EqualTo(new[] { "honesty" }));
}
}
[Test]
public void AtMostThreeValuesAreLookedAtMoreClosely()
{
var cardSort = new BflCardSort();
cardSort.ChooseFocus(["honesty", "openness"]);
cardSort.ChooseFocus(["honesty", "openness", "respect", "care"]);
using (Assert.EnterMultipleScope())
{
Assert.That(cardSort.Focus, Has.Count.EqualTo(BflCardSort.MAX_FOCUS));
Assert.That(cardSort.Focus.Take(2), Is.EqualTo(new[] { "honesty", "openness" }));
}
}
[Test]
public void ValuesChosenEarlierKeepTheirPlace()
{
var cardSort = new BflCardSort();
cardSort.ChooseFocus(["openness"]);
cardSort.ChooseFocus(["honesty", "openness"]);
Assert.That(cardSort.Focus, Is.EqualTo(new[] { "openness", "honesty" }));
}
[Test]
public async Task OnlyValuesWhichExistCountAsLookedAtMoreClosely()
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
var cardSort = new BflCardSort();
var value = cardSort.AddOwnValue("Curiosity", string.Empty)!;
cardSort.Focus = ["value_of_another_deck", "honesty", "honesty", value.Id, "openness", "respect"];
var focus = cardSort.FocusIn(deck);
using (Assert.EnterMultipleScope())
{
Assert.That(focus, Is.EqualTo(new[] { "honesty", value.Id, "openness" }));
Assert.That(cardSort.NameOf(value.Id, deck), Is.EqualTo("Curiosity"));
Assert.That(cardSort.NameOf("honesty", deck), Is.EqualTo("Honesty"));
Assert.That(cardSort.NameOf("value_of_another_deck", deck), Is.Null);
}
}
}
@@ -73,6 +73,35 @@ public sealed class BflFieldCatalogTests
Assert.That(stepsInOrder, Is.EqualTo(BflStep.All));
}
[Test]
public void TheValuesStepShowsTheThreeSectionsOfLarasDialogueLogicInTheirOrder()
{
var sections = BflFieldCatalog.ForStep(BflStep.VALUES_AND_PERSPECTIVES).Select(field => field.Section).Distinct();
Assert.That(sections, Is.EqualTo(new[] { BflFormSection.WHAT_MATTERS_TO_ME, BflFormSection.WHAT_TOUCHES_ME, BflFormSection.WHAT_MOVES_OTHERS }));
}
[Test]
public void TheFieldsOfASectionFollowEachOtherAndHaveAHeading()
{
using (Assert.EnterMultipleScope())
{
foreach (var step in BflStep.All)
{
var sections = BflFieldCatalog.ForStep(step).Select(field => field.Section).ToList();
var runs = sections.Where((section, index) => index == 0 || sections[index - 1] != section).ToList();
Assert.That(runs, Is.Unique, $"The fields of a section of {step} do not follow each other.");
Assert.That(runs.Where(section => section is not BflFormSection.NONE).Select(section => section.Title), Has.None.Empty, $"A section of {step} has no heading.");
}
}
}
[Test]
public void OnlyTheSectionAboutWhatMattersHoldsTheCardSort()
{
Assert.That(Enum.GetValues<BflFormSection>().Where(section => section.HasCardSort), Is.EqualTo(new[] { BflFormSection.WHAT_MATTERS_TO_ME }));
}
[Test]
public void EveryStepHasAFormWithATitleAndADescription()
{
@@ -195,7 +195,39 @@ public sealed class BflShareModelBuilderTests
Assert.That(Build(forms: forms, conversations: conversations), Does.Not.Contain("\r"));
}
private static string Build(Dictionary<BflStep, BflStepFormData>? forms = null, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, IReadOnlyDictionary<BflResultKind, BflResult>? results = null, IReadOnlyDictionary<BflStep, IReadOnlyList<BflConversationMessage>>? conversations = null, IReadOnlyList<BflMaterial>? materials = null, IReadOnlyCollection<BflResearchTopic>? researchTopics = null, bool includePersonalDisclosures = false) => BflShareModelBuilder.Build(new BflShareInput(
[Test]
public async Task TheCardSortIsSharedWithTheNamesThePersonSaw()
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
var forms = Forms();
var cardSort = new BflCardSort();
cardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
var curiosity = cardSort.AddOwnValue("Curiosity", "Ask questions")!;
cardSort.ChooseFocus(["honesty", curiosity.Id]);
forms[BflStep.VALUES_AND_PERSPECTIVES].CardSort = cardSort;
var session = Build(forms: forms, valueDeck: deck);
using (Assert.EnterMultipleScope())
{
Assert.That(session, Does.Contain("**Card sort:**\n\n- **Honesty:** Especially important\n"));
Assert.That(session, Does.Contain($"- **Safety:** {BflValueCategory.NONE.Title}\n"));
Assert.That(session, Does.Contain("- **Own values:** Curiosity (Ask questions)\n"));
Assert.That(session, Does.Contain("- **To look at more closely:** Honesty, Curiosity\n"));
}
}
[Test]
public async Task AnUntouchedCardSortIsNotShared()
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
var forms = Forms();
forms[BflStep.VALUES_AND_PERSPECTIVES].CardSort = new();
Assert.That(Build(forms: forms, valueDeck: deck), Does.Not.Contain("Card sort"));
}
private static string Build(Dictionary<BflStep, BflStepFormData>? forms = null, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, IReadOnlyDictionary<BflResultKind, BflResult>? results = null, IReadOnlyDictionary<BflStep, IReadOnlyList<BflConversationMessage>>? conversations = null, IReadOnlyList<BflMaterial>? materials = null, IReadOnlyCollection<BflResearchTopic>? researchTopics = null, bool includePersonalDisclosures = false, BflValueDeck? valueDeck = null) => BflShareModelBuilder.Build(new BflShareInput(
forms ?? Forms(),
workStates ?? new Dictionary<BflStep, BflWorkState>(),
results ?? new Dictionary<BflResultKind, BflResult>(),
@@ -205,7 +237,8 @@ public sealed class BflShareModelBuilderTests
includePersonalDisclosures,
"26.11.2",
NOW,
CultureInfo.InvariantCulture));
CultureInfo.InvariantCulture,
valueDeck));
private static Dictionary<BflStep, BflStepFormData> Forms() => BflStep.All.ToDictionary(step => step, _ => new BflStepFormData());
@@ -1,3 +1,6 @@
using System.Security.Cryptography;
using System.Text;
using AIStudio.Assistants.BeyondFactsLab;
namespace AIStudio.Tests.BeyondFactsLab;
@@ -167,6 +170,62 @@ public sealed class BflStalenessTests
Assert.That(BflStaleness.FingerprintOf(first), Is.Not.EqualTo(BflStaleness.FingerprintOf(second)));
}
[Test]
public void WithoutACardSortTheFingerprintStaysAsItWasBeforeTheCardSort()
{
var withoutCardSort = new BflStepFormData();
withoutCardSort.Set(BflFieldCatalog.VALUES_AND_CONCERNS, "Text");
var withEmptyCardSort = new BflStepFormData { CardSort = new() };
withEmptyCardSort.Set(BflFieldCatalog.VALUES_AND_CONCERNS, "Text");
// How the lab computed the fingerprint of this form before it had a card sort:
var before = Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes($"{BflFieldCatalog.VALUES_AND_CONCERNS}\0Text\0")));
using (Assert.EnterMultipleScope())
{
Assert.That(BflStaleness.FingerprintOf(withoutCardSort), Is.EqualTo(before));
Assert.That(BflStaleness.FingerprintOf(withEmptyCardSort), Is.EqualTo(before));
}
}
[Test]
public void TheFingerprintCountsTheCardSort()
{
var empty = new BflStepFormData();
var sorted = new BflStepFormData { CardSort = new() };
sorted.CardSort.Sort("honesty", BflValueCategory.ESPECIALLY_IMPORTANT);
var sortedOtherwise = new BflStepFormData { CardSort = new() };
sortedOtherwise.CardSort.Sort("honesty", BflValueCategory.UNCLEAR);
var withOwnValue = new BflStepFormData { CardSort = new() };
withOwnValue.CardSort.AddOwnValue("Curiosity", string.Empty);
var fingerprints = new[] { empty, sorted, sortedOtherwise, withOwnValue }.Select(BflStaleness.FingerprintOf).ToList();
Assert.That(fingerprints, Is.Unique);
}
[Test]
public void TheOrderOfTheValuesToLookAtMoreCloselyIsNoChange()
{
var first = new BflStepFormData { CardSort = new() { Focus = ["honesty", "openness"] } };
var second = new BflStepFormData { CardSort = new() { Focus = ["openness", "honesty"] } };
Assert.That(BflStaleness.FingerprintOf(first), Is.EqualTo(BflStaleness.FingerprintOf(second)));
}
[Test]
public void AChangedCardSortWeighsLikeChangedDetails()
{
var form = new BflStepFormData();
var workStates = new Dictionary<BflStep, BflWorkState>();
Confirm(workStates, BflStep.VALUES_AND_PERSPECTIVES, form);
form.CardSort = new();
form.CardSort.Sort("openness", BflValueCategory.ALSO_IMPORTANT);
Assert.That(BflStaleness.Of(BflStep.VALUES_AND_PERSPECTIVES, workStates, Forms((BflStep.VALUES_AND_PERSPECTIVES, form))), Is.EqualTo(BflWorkStateStatus.DETAILS_CHANGED));
}
[Test]
public void AConfirmationRemembersOnlyEarlierSteps()
{
@@ -0,0 +1,100 @@
using System.Globalization;
using AIStudio.Assistants.BeyondFactsLab;
namespace AIStudio.Tests.BeyondFactsLab;
/// <summary>
/// Checks the value deck of the BeyondFacts Lab: that the app comes with it in every language it names, that every
/// language has the same values in the same rounds, and that a deck with a wrong form is refused.
/// </summary>
/// <remarks>
/// The tests run a development build, which reads the decks from its output folder: the project file copies every
/// embedded file there as well.
/// </remarks>
[TestFixture]
public sealed class BflValueDeckTests
{
private static IEnumerable<string> Languages() => BflValueDeck.LANGUAGES.Order(StringComparer.Ordinal);
[TestCaseSource(nameof(Languages))]
public async Task EveryLanguageHasAValidDeck(string language)
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo(language));
using (Assert.EnterMultipleScope())
{
Assert.That(deck.Problems(), Is.Empty);
Assert.That(deck.Cards, Has.Count.EqualTo(BflValueDeck.ROUNDS * BflValueDeck.VALUES_PER_ROUND));
Assert.That(deck.Citation, Does.Contain("Miller").And.Contain("2001").And.Contain("Personal Values Card Sort"));
}
}
[Test]
public async Task EveryLanguageHasTheSameValuesInTheSameRounds()
{
var english = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
foreach (var language in Languages())
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo(language));
Assert.That(deck.Rounds.Select(round => round.Select(card => card.Id)), Is.EqualTo(english.Rounds.Select(round => round.Select(card => card.Id))), language);
}
}
[TestCase("de-DE", "values.de.json")]
[TestCase("de-AT", "values.de.json")]
[TestCase("en-US", "values.en.json")]
[TestCase("fr-FR", "values.en.json")]
[TestCase("", "values.en.json")]
public void TheAppShowsTheDeckOfItsLanguageOrElseTheEnglishOne(string culture, string fileName)
{
Assert.That(BflValueDeck.PathOf(CultureInfo.GetCultureInfo(culture)), Does.EndWith($"/{fileName}"));
}
[Test]
public async Task AValueIsFoundByItsId()
{
var deck = await BflValueDeck.LoadAsync(CultureInfo.GetCultureInfo("en"));
using (Assert.EnterMultipleScope())
{
Assert.That(deck.Find("honesty")?.Name, Is.EqualTo("Honesty"));
Assert.That(deck.Find("unknown"), Is.Null);
}
}
[Test]
public void ADeckWithAWrongNumberOfRoundsOrValuesIsRefused()
{
var deck = ValidDeck();
deck.Rounds.RemoveAt(2);
deck.Rounds[0].RemoveAt(3);
Assert.That(deck.Problems(), Has.Count.EqualTo(2));
}
[Test]
public void ADeckWithAnIdTwiceOrAValueWithoutItsTextsIsRefused()
{
var deck = ValidDeck();
deck.Rounds[1][0].Id = deck.Rounds[0][0].Id;
deck.Rounds[2][0].Definition = " ";
Assert.That(deck.Problems(), Has.Count.EqualTo(2));
}
[Test]
public void ADeckWithoutItsSourceIsRefused()
{
var deck = ValidDeck();
deck.Citation = string.Empty;
Assert.That(deck.Problems(), Has.One.Contains("source"));
}
private static BflValueDeck ValidDeck() => new()
{
Citation = "Miller et al. (2001)",
Rounds = [.. Enumerable.Range(0, BflValueDeck.ROUNDS).Select(round => Enumerable.Range(0, BflValueDeck.VALUES_PER_ROUND).Select(index => new BflValueCard { Id = $"value_{round}_{index}", Name = "Name", Definition = "Definition" }).ToList())],
};
}
+3
View File
@@ -71,6 +71,9 @@ public static partial class JsonTestRoots
yield return Case(new(typeof(BflResearch), BeyondFactsLabJson.PERSISTENCE));
yield return Case(new(typeof(Guid?), BeyondFactsLabJson.PERSISTENCE), "selected preparation");
// The value deck of the BeyondFacts Lab, which comes with the app and is read like its files:
yield return Case(new(typeof(BflValueDeck), BeyondFactsLabJson.PERSISTENCE), "value deck");
// The presets and the stored results of the Model Comparison assistant:
yield return Case(new(typeof(ModelComparisonPreset), ModelComparisonJson.PERSISTENCE));
yield return Case(new(typeof(ModelComparisonRecord), ModelComparisonJson.PERSISTENCE));