Skip to content

Commit 040b70e

Browse files
authored
Arduino ci (#1)
* initial arduino-ci * add unit tests
1 parent e204aea commit 040b70e

File tree

8 files changed

+219
-21
lines changed

8 files changed

+219
-21
lines changed

.arduino-ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
# Choosing to run compilation tests on 2 different Arduino platforms
3+
platforms:
4+
- uno
5+
- leonardo
6+
- due
7+
- zero
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
arduino_ci:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: Arduino-CI/action@master
13+
# Arduino-CI/action@v0.1.1

Angle.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
22
// FILE: Angle.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.8
4+
// VERSION: 0.1.9
55
// PURPOSE: library for Angle math for Arduino
66
// URL: https://github.com/RobTillaart/Angle
77
// http://forum.arduino.cc/index.php?topic=339402
88
//
9-
// Released to the public domain
10-
// 0.1.8 2020-05-27 update library.json
11-
// 0.1.7 2020-03-26 refactor #pragma once
9+
// 0.1.9 2020-12-10 Arduino ci
10+
// 0.1.8 2020-05-27 update library.json
11+
// 0.1.7 2020-03-26 refactor #pragma once
1212
// 0.1.06 - fixed bug negative values.
1313
// 0.1.05 - added AngleFormat proxy added 03/03/15 by Christoper Andrews.
1414
// 0.1.04 - changed thousands in tenthousands, string constructor

Angle.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: Angle.h
44
// AUTHOR: Rob dot Tillaart at gmail dot com
5-
// VERSION: 0.1.8
5+
// VERSION: 0.1.9
66
// PURPOSE: angle library for Arduino
77
// HISTORY: See angle.cpp
88
//
@@ -13,7 +13,7 @@
1313
#include "Arduino.h"
1414
#include "Printable.h"
1515

16-
#define ANGLE_LIB_VERSION "0.1.8"
16+
#define ANGLE_LIB_VERSION "0.1.9"
1717

1818
class Angle;
1919

@@ -37,10 +37,10 @@ class Angle: public Printable
3737
Angle(double alpha);
3838
Angle(char * str);
3939

40-
int sign() { return neg?-1:1; };
41-
int degree() { return d; };
42-
int minute() { return m; };
43-
int second() { return s; };
40+
int sign() { return neg ? -1 : 1; };
41+
int degree() { return d; };
42+
int minute() { return m; };
43+
int second() { return s; };
4444
int tenthousand() { return t; };
4545

4646
size_t printTo(Print& p) const { return printTo( p, T ); }

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/Angle/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Angle/blob/master/LICENSE)
4+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Angle.svg?maxAge=3600)](https://github.com/RobTillaart/Angle/releases)
5+
6+
17
# Angle
28

3-
Arduino library for basic math for Angles in degrees, minute, seconds
9+
Arduino library for basic math for Angles in degrees, minute, seconds and tenthousands.
410

511
## Description
612

@@ -9,18 +15,20 @@ in degrees, minutes seconds and tenthousands. The class was created to be
915
able to print an angle with minutes and seconds instead of as a floating point
1016
or radians.
1117

12-
To make the library more useful basic math (+ - \* / )
13-
and comparisons ( == != < <= > >= )
14-
are added to the class.
18+
To make the library more useful basic math ( + - \* / )
19+
and comparisons ( == != < <= > >= ) are added to the class.
20+
21+
## Interface
22+
23+
There are three constructors
24+
- **Angle(int dd=0, int mm=0, int ss=0, int tt=0)**
25+
- **Angle(double alpha)**
26+
- **Angle(char \* str)** // str represents a double as string e.g. "45.31234"
1527

1628
## Operation
1729

18-
There are three constructors
19-
* Angle(int dd=0, int mm=0, int ss=0, int tt=0);
20-
* Angle(double alpha);
21-
* Angle(char * str); // str represents a double as string e.g. "45.31234"
30+
See examples
2231

23-
For other functions and operators check examples for now.
2432

2533
## Note
2634
The library has not been tested extensively and it could still contain

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"type": "git",
2121
"url": "https://github.com/RobTillaart/Angle.git"
2222
},
23-
"version":"0.1.8",
23+
"version":"0.1.9",
2424
"frameworks": "arduino",
2525
"platforms": "*"
2626
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Angle
2-
version=0.1.8
2+
version=0.1.9
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Library to convert between floating point angle to minutes hours representation.

test/unit_test_001.cpp

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
//
2+
// FILE: unit_test_001.cpp
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// DATE: 2020-12-03
6+
// PURPOSE: unit tests for the Angle library
7+
// https://github.com/RobTillaart/Angle
8+
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
9+
//
10+
11+
// supported assertions
12+
// ----------------------------
13+
// assertEqual(expected, actual)
14+
// assertNotEqual(expected, actual)
15+
// assertLess(expected, actual)
16+
// assertMore(expected, actual)
17+
// assertLessOrEqual(expected, actual)
18+
// assertMoreOrEqual(expected, actual)
19+
// assertTrue(actual)
20+
// assertFalse(actual)
21+
// assertNull(actual)
22+
23+
#include <ArduinoUnitTests.h>
24+
25+
#include "Arduino.h"
26+
#include "Angle.h"
27+
28+
29+
unittest_setup()
30+
{
31+
}
32+
33+
unittest_teardown()
34+
{
35+
}
36+
37+
unittest(test_constructors)
38+
{
39+
Angle a(1, 2, 3, 4);
40+
Angle b(-45, 30);
41+
Angle n(0);
42+
Angle d(5.25);
43+
Angle s("37.25");
44+
45+
assertEqual(1, a.sign());
46+
assertEqual(1, a.degree());
47+
assertEqual(2, a.minute());
48+
assertEqual(3, a.second());
49+
assertEqual(4, a.tenthousand());
50+
51+
assertEqual(-1, b.sign());
52+
assertEqual(45, b.degree());
53+
assertEqual(30, b.minute());
54+
assertEqual(0, b.second());
55+
assertEqual(0, b.tenthousand());
56+
57+
assertEqual(1, n.sign());
58+
assertEqual(0, n.degree());
59+
assertEqual(0, n.minute());
60+
assertEqual(0, n.second());
61+
assertEqual(0, n.tenthousand());
62+
63+
assertEqual(1, d.sign());
64+
assertEqual(5, d.degree());
65+
assertEqual(15, d.minute());
66+
assertEqual(0, d.second());
67+
assertEqual(0, d.tenthousand());
68+
69+
assertEqual(1, s.sign());
70+
assertEqual(37, s.degree());
71+
assertEqual(15, s.minute());
72+
assertEqual(0, s.second());
73+
assertEqual(0, s.tenthousand());
74+
}
75+
76+
unittest(test_toDouble)
77+
{
78+
Angle a(1, 2, 3, 4);
79+
Angle b(-45, 30);
80+
Angle n(0);
81+
Angle d(5.25);
82+
Angle s("37.25");
83+
84+
float fa = a.toDouble();
85+
float fb = b.toDouble();
86+
float fn = n.toDouble();
87+
float fd = d.toDouble();
88+
float fs = s.toDouble();
89+
90+
assertMoreOrEqual(2, fa);
91+
assertMoreOrEqual(-45, fb);
92+
assertEqual(0, fn);
93+
assertMoreOrEqual(6, fd);
94+
assertMoreOrEqual(38, fs);
95+
}
96+
97+
unittest(test_Radians)
98+
{
99+
Angle a(1, 2, 3, 4);
100+
Angle b(-75, 30);
101+
Angle n(0);
102+
Angle d(5.25);
103+
Angle s("91.25");
104+
105+
float ra = a.toRadians();
106+
float rb = b.toRadians();
107+
float rn = n.toRadians();
108+
float rd = d.toRadians();
109+
float rs = s.toRadians();
110+
111+
assertMoreOrEqual(1, ra);
112+
assertMoreOrEqual(-1, rb);
113+
assertEqual(0, rn);
114+
assertMoreOrEqual(0.1, rd);
115+
assertMoreOrEqual(PI, rs);
116+
}
117+
118+
119+
// mainly tests if operators still work, not a quality test (yet)
120+
unittest(test_math)
121+
{
122+
Angle a(1, 2, 3, 4);
123+
Angle b(-45, 30);
124+
Angle n(0);
125+
Angle d(5.25);
126+
Angle s("91.25");
127+
128+
Angle x = a + b - n + d + s;
129+
assertNotEqual(0, x.toDouble());
130+
131+
x *= 2;
132+
assertNotEqual(0, x.toDouble());
133+
x /= 2;
134+
assertNotEqual(0, x.toDouble());
135+
x += 2;
136+
assertNotEqual(0, x.toDouble());
137+
x -= 2;
138+
assertNotEqual(0, x.toDouble());
139+
140+
x = a * 2;
141+
assertNotEqual(0, x.toDouble());
142+
x = a / 2;
143+
assertNotEqual(0, x.toDouble());
144+
x = a + 2;
145+
assertNotEqual(0, x.toDouble());
146+
x = a - 2;
147+
assertNotEqual(0, x.toDouble());
148+
149+
x = -x;
150+
assertNotEqual(0, x.toDouble());
151+
}
152+
153+
154+
unittest(test_compare)
155+
{
156+
Angle a(1, 2, 3, 4);
157+
Angle b(-45, 30);
158+
159+
assertTrue(a == a);
160+
assertTrue(a != b);
161+
assertTrue(b <= a);
162+
assertTrue(b < a);
163+
assertTrue(a > b);
164+
assertTrue(a >= b);
165+
}
166+
167+
168+
unittest_main()
169+
170+
// --------

0 commit comments

Comments
 (0)