forked from dotnet/iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharlieplexLayout.cs
105 lines (97 loc) · 4.92 KB
/
CharlieplexLayout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Iot.Device.Multiplexing;
using Xunit;
namespace Charlietests
{
public class CharlieplexLayoutTests
{
[Fact]
public void TwoPinLayout()
{
var pins = new int[] { 1, 2 };
CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
Assert.True(nodes.Length == 2);
Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
}
[Fact]
public void ThreePinLayout()
{
var pins = new int[] { 1, 2, 3 };
CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
Assert.True(nodes.Length == 6);
Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
Assert.True(nodes[4].Anode == 1 && nodes[4].Cathode == 3);
Assert.True(nodes[5].Anode == 3 && nodes[5].Cathode == 1);
}
[Fact]
public void FourPinLayout()
{
var pins = new int[] { 1, 2, 3, 4 };
CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
Assert.True(true);
Assert.True(nodes.Length == 12);
Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
Assert.True(nodes[4].Anode == 3 && nodes[4].Cathode == 4);
Assert.True(nodes[5].Anode == 4 && nodes[5].Cathode == 3);
Assert.True(nodes[6].Anode == 1 && nodes[6].Cathode == 3);
Assert.True(nodes[7].Anode == 3 && nodes[7].Cathode == 1);
Assert.True(nodes[8].Anode == 2 && nodes[8].Cathode == 4);
Assert.True(nodes[9].Anode == 4 && nodes[9].Cathode == 2);
Assert.True(nodes[10].Anode == 1 && nodes[10].Cathode == 4);
Assert.True(nodes[11].Anode == 4 && nodes[11].Cathode == 1);
}
[Fact]
public void FourPinLayoutLimitEight()
{
var pins = new int[] { 1, 2, 3, 4 };
CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins, 8);
Assert.True(true);
Assert.True(nodes.Length == 8);
Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
Assert.True(nodes[4].Anode == 3 && nodes[4].Cathode == 4);
Assert.True(nodes[5].Anode == 4 && nodes[5].Cathode == 3);
Assert.True(nodes[6].Anode == 1 && nodes[6].Cathode == 3);
Assert.True(nodes[7].Anode == 3 && nodes[7].Cathode == 1);
}
[Fact]
public void FivePinLayout()
{
var pins = new int[] { 1, 2, 3, 4, 5 };
CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
Assert.True(true);
Assert.True(nodes.Length == 20);
Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
Assert.True(nodes[4].Anode == 3 && nodes[4].Cathode == 4);
Assert.True(nodes[5].Anode == 4 && nodes[5].Cathode == 3);
Assert.True(nodes[6].Anode == 4 && nodes[6].Cathode == 5);
Assert.True(nodes[7].Anode == 5 && nodes[7].Cathode == 4);
Assert.True(nodes[8].Anode == 1 && nodes[8].Cathode == 3);
Assert.True(nodes[9].Anode == 3 && nodes[9].Cathode == 1);
Assert.True(nodes[10].Anode == 2 && nodes[10].Cathode == 4);
Assert.True(nodes[11].Anode == 4 && nodes[11].Cathode == 2);
Assert.True(nodes[12].Anode == 3 && nodes[12].Cathode == 5);
Assert.True(nodes[13].Anode == 5 && nodes[13].Cathode == 3);
Assert.True(nodes[14].Anode == 1 && nodes[14].Cathode == 4);
Assert.True(nodes[15].Anode == 4 && nodes[15].Cathode == 1);
Assert.True(nodes[16].Anode == 2 && nodes[16].Cathode == 5);
Assert.True(nodes[17].Anode == 5 && nodes[17].Cathode == 2);
Assert.True(nodes[18].Anode == 1 && nodes[18].Cathode == 5);
Assert.True(nodes[19].Anode == 5 && nodes[19].Cathode == 1);
}
}
}