WPF-free geometry behind the visual controls: wrapped-grid layout with O(1) index/offset mapping and keyboard targets, nice axis ticks, min/max decimation, zoom/pan transforms, monotone curve editing rules, filmstrip and heatmap cell layout, an LRU cache and device-pixel snapping, with tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Titano.Testing;
|
|
using Titano.Ui.Visuals;
|
|
|
|
namespace Titano.App.Tests.Visuals;
|
|
|
|
public sealed class LruCacheTests
|
|
{
|
|
[Test]
|
|
public void EvictsTheLeastRecentlyUsedEntry()
|
|
{
|
|
var cache = new LruCache<int, string>(2);
|
|
cache.Set(1, "a");
|
|
cache.Set(2, "b");
|
|
Assert.True(cache.TryGet(1, out _));
|
|
cache.Set(3, "c");
|
|
Assert.False(cache.TryGet(2, out _));
|
|
Assert.True(cache.TryGet(1, out var one));
|
|
Assert.Equal("a", one);
|
|
Assert.True(cache.TryGet(3, out _));
|
|
Assert.Equal(2, cache.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void ReplacingAValueRefreshesItsRecency()
|
|
{
|
|
var cache = new LruCache<int, string>(2);
|
|
cache.Set(1, "a");
|
|
cache.Set(2, "b");
|
|
cache.Set(1, "a2");
|
|
cache.Set(3, "c");
|
|
Assert.True(cache.TryGet(1, out var value));
|
|
Assert.Equal("a2", value);
|
|
Assert.False(cache.TryGet(2, out _));
|
|
}
|
|
|
|
[Test]
|
|
public void ShrinkingCapacityEvictsOldestFirst()
|
|
{
|
|
var cache = new LruCache<int, int>(10);
|
|
for (var i = 0; i < 10; i++) cache.Set(i, i);
|
|
cache.Capacity = 3;
|
|
Assert.Equal(3, cache.Count);
|
|
for (var i = 0; i < 7; i++) Assert.False(cache.TryGet(i, out _));
|
|
for (var i = 7; i < 10; i++) Assert.True(cache.TryGet(i, out _));
|
|
}
|
|
|
|
[Test]
|
|
public void RemoveAndClear()
|
|
{
|
|
var cache = new LruCache<string, int>(4);
|
|
cache.Set("x", 1);
|
|
cache.Set("y", 2);
|
|
Assert.True(cache.Remove("x"));
|
|
Assert.False(cache.Remove("x"));
|
|
cache.Clear();
|
|
Assert.Equal(0, cache.Count);
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => _ = new LruCache<int, int>(0));
|
|
}
|
|
}
|