-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more tests * Fix config * Test (#8) * Try and get it on master? * Add readme badge * Fix config * Test solid side * Add build status * Wrap filesystem operations * Remove service option * Remove --service from service * Only delete the pid file if contents match current pid * Don't try to read a non-existent file * Add tests for special file * Don't check for overflows now * Start IoC container with file access * Make a move to reactive updates instead of timed ones * Only do reactive render * Allow specifying fps * Make sure we always render the first frame * Make a faster file implementation * Use exponential average * Update the readme
- Loading branch information
1 parent
4c5ee31
commit c759cc6
Showing
38 changed files
with
951 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using keyboards; | ||
using keyboards.Monitors; | ||
|
||
namespace UnitTests | ||
{ | ||
public class FakeContainer : IControlContainer | ||
{ | ||
public HashSet<IMonitor> Monitors { get; set; } | ||
|
||
public IFile File(string filename) | ||
{ | ||
return new FakeFile(filename); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Threading.Tasks; | ||
using keyboards; | ||
|
||
namespace UnitTests | ||
{ | ||
public class FakeFile : IFile | ||
{ | ||
public FakeFile(string filename) | ||
{ | ||
} | ||
|
||
public bool Exists { get; internal set; } | ||
|
||
public bool HasPermission { get; internal set; } | ||
|
||
public string Contents { get; internal set; } | ||
|
||
public Task Commit(string contents) | ||
{ | ||
Contents = contents; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<string> Read() | ||
{ | ||
return Task.FromResult(Contents); | ||
} | ||
|
||
public Task<string[]> Lines() | ||
{ | ||
return Task.FromResult(Contents.Split('\n')); | ||
} | ||
|
||
public void Delete() | ||
{ | ||
Exists = false; | ||
Contents = string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Threading.Tasks; | ||
using keyboards; | ||
using keyboards.ColorSpace; | ||
using keyboards.Filters; | ||
using keyboards.Sides; | ||
using NUnit.Framework; | ||
|
||
namespace UnitTests.Sides | ||
{ | ||
public class SolidTests | ||
{ | ||
private readonly IFile _fixtureFile = new FakeFile("test-color"); | ||
|
||
[SetUp] | ||
public async Task CreateFixture() | ||
{ | ||
await _fixtureFile.Commit("FF00FF"); | ||
} | ||
|
||
[TearDown] | ||
public void ResetFixture() | ||
{ | ||
_fixtureFile.Delete(); | ||
} | ||
|
||
[Test] | ||
public void TestSolidColor() | ||
{ | ||
var side = new Solid(Rgb.FromHex("FFFFFF")) {Led = _fixtureFile}; | ||
side.Commit(new IFilter[] { }); | ||
Assert.AreEqual("FFFFFF", side.Led.Contents); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using keyboards; | ||
using NUnit.Framework; | ||
|
||
namespace UnitTests | ||
{ | ||
public class SpecialFileTests | ||
{ | ||
private const string NoExistsPath = "noexists"; | ||
private static string ExistsPath => Path.GetTempFileName(); | ||
|
||
private static string NoPermsPath | ||
{ | ||
get | ||
{ | ||
var path = Path.GetTempFileName(); | ||
File.SetAttributes(path, FileAttributes.ReadOnly); | ||
return path; | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanCheckExists() | ||
{ | ||
var exists = new SpecialFile(ExistsPath); | ||
var noExists = new SpecialFile(NoExistsPath); | ||
|
||
Assert.IsTrue(exists.Exists); | ||
Assert.IsFalse(noExists.Exists); | ||
} | ||
|
||
[Test] | ||
public void HasWritePermissionsWithWritableFile() | ||
{ | ||
var canWrite = new SpecialFile(ExistsPath); | ||
|
||
Assert.IsTrue(canWrite.HasPermission); | ||
} | ||
|
||
[Test] | ||
public void NoPermissionsWithReadOnlyFile() | ||
{ | ||
var noWrite = new SpecialFile(NoPermsPath); | ||
Assert.IsFalse(noWrite.HasPermission); | ||
} | ||
|
||
[Test] | ||
public void PermissionsToNonExistingFile() | ||
{ | ||
var noExists = new SpecialFile(NoExistsPath); | ||
Assert.IsTrue(noExists.HasPermission); | ||
} | ||
|
||
[Test] | ||
public async Task CanWriteToRegularFile() | ||
{ | ||
var exists = new SpecialFile(Path.GetTempFileName()); | ||
await exists.Commit("test"); | ||
Assert.AreEqual("test", await exists.Read()); | ||
Assert.AreEqual("test", exists.Contents); | ||
Assert.AreEqual("test", (await exists.Lines())[0]); | ||
} | ||
|
||
[Test] | ||
public async Task CannotWriteToUnwritableFile() | ||
{ | ||
var no = new SpecialFile(NoPermsPath); | ||
await no.Commit("test"); | ||
Assert.AreEqual("", no.Contents); | ||
} | ||
|
||
[Test] | ||
public void CanDeleteNonExistentFile() | ||
{ | ||
Assert.IsFalse(File.Exists(NoExistsPath)); | ||
var no = new SpecialFile(NoExistsPath); | ||
no.Delete(); | ||
Assert.DoesNotThrow(() => no.Delete()); | ||
} | ||
|
||
[Test] | ||
public void CanDeleteRegularFile() | ||
{ | ||
var path = ExistsPath; | ||
Assert.IsTrue(File.Exists(path)); | ||
var file = new SpecialFile(path); | ||
Assert.DoesNotThrow(() => file.Delete()); | ||
Assert.IsFalse(File.Exists(path)); | ||
} | ||
|
||
[Test] | ||
public void CanDeleteReadOnlyFile() | ||
{ | ||
var path = NoPermsPath; | ||
Assert.IsTrue(File.Exists(path)); | ||
var file = new SpecialFile(path); | ||
Assert.DoesNotThrow(() => file.Delete()); | ||
Assert.IsTrue(File.Exists(path)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using keyboards.Monitors; | ||
|
||
namespace keyboards | ||
{ | ||
public class ControlContainer : IControlContainer | ||
{ | ||
public IFile File(string filename) | ||
{ | ||
return new FastFile(filename); | ||
} | ||
|
||
public HashSet<IMonitor> Monitors { get; set; } = new HashSet<IMonitor>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IO; | ||
|
||
namespace keyboards | ||
{ | ||
/// <summary> | ||
/// A file implementation that assumes the world won't change | ||
/// </summary> | ||
public class FastFile : SpecialFile | ||
{ | ||
private bool? _existsCache; | ||
private bool? _hasPermissionsCache; | ||
|
||
public new bool Exists | ||
{ | ||
get | ||
{ | ||
if (_existsCache == null) | ||
{ | ||
_existsCache = base.Exists; | ||
} | ||
|
||
return _existsCache.Value; | ||
} | ||
} | ||
|
||
public new bool HasPermission | ||
{ | ||
get | ||
{ | ||
if (_hasPermissionsCache == null) | ||
{ | ||
_hasPermissionsCache = base.HasPermission; | ||
} | ||
|
||
return _hasPermissionsCache.Value; | ||
} | ||
} | ||
|
||
public FastFile(string filename) : base(filename) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.