mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 VolumeConverter
This commit is contained in:
parent
4ff96f0da5
commit
20e7576512
29
libraries/VolumeConverter/.arduino-ci.yml
Normal file
29
libraries/VolumeConverter/.arduino-ci.yml
Normal file
@ -0,0 +1,29 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
# selected only those that work
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
4
libraries/VolumeConverter/.github/FUNDING.yml
vendored
Normal file
4
libraries/VolumeConverter/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/VolumeConverter/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/VolumeConverter/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/VolumeConverter/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/VolumeConverter/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/VolumeConverter/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/VolumeConverter/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
11
libraries/VolumeConverter/CHANGELOG.md
Normal file
11
libraries/VolumeConverter/CHANGELOG.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Change Log VolumeConverter
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.0] - 2023-08-29
|
||||
- initial version
|
||||
|
21
libraries/VolumeConverter/LICENSE
Normal file
21
libraries/VolumeConverter/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2023 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
135
libraries/VolumeConverter/README.md
Normal file
135
libraries/VolumeConverter/README.md
Normal file
@ -0,0 +1,135 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/VolumeConverter/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/VolumeConverter/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/VolumeConverter/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/VolumeConverter/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/VolumeConverter/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/VolumeConverter.svg)](https://github.com/RobTillaart/VolumeConverter/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/VolumeConverter/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/VolumeConverter.svg?maxAge=3600)](https://github.com/RobTillaart/VolumeConverter/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/VolumeConverter.svg)](https://registry.platformio.org/libraries/robtillaart/VolumeConverter)
|
||||
|
||||
|
||||
# VolumeConverter
|
||||
|
||||
Arduino library to convert volume units.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
VolumeConverter is a library containing a VolumeConverter class.
|
||||
|
||||
It consists of setters to set a certain volume in one of the
|
||||
many supported units. Internally it is converted to liters.
|
||||
Then the user can use a getter to get the volume in one of the
|
||||
supported units.
|
||||
|
||||
Besides conversion the class also allows one to add different
|
||||
units and convert them.
|
||||
|
||||
The purpose of the library is conversion and can be used for
|
||||
educational programs too.
|
||||
|
||||
The library is open for additions, including obscure volume metrics
|
||||
and volume related math functions and constants.
|
||||
Also good examples (e.g. educational) are welcome.
|
||||
|
||||
|
||||
#### Accuracy
|
||||
|
||||
As the library uses floats the accuracy is limited especially
|
||||
if one tries to add or convert the extremes of the scales.
|
||||
E.g. Long tons to teaspoons will loose significant digits.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
|
||||
```cpp
|
||||
#include "VolumeConverter.h"
|
||||
```
|
||||
|
||||
Internal representation is the liter as it the ISO standard.
|
||||
|
||||
## Interface
|
||||
|
||||
|
||||
#### Constructor
|
||||
|
||||
- **VolumeConverter()** sets the internal value to 0.
|
||||
|
||||
#### Setters
|
||||
|
||||
- **void setLiters(float value = 0)**
|
||||
- **void setMilliLiters(float value = 0)**
|
||||
- **void setCubicMeters(float value = 0)**
|
||||
- **void setLongTons(float value = 0)**
|
||||
- **void setShortTons(float value = 0)**
|
||||
- **void setBarrels(float value = 0)**
|
||||
- **void setGallons(float value = 0)**
|
||||
- **void setQuarts(float value = 0)**
|
||||
- **void setPints(float value = 0)**
|
||||
- **void setCups(float value = 0)**
|
||||
- **void setFluidOunces(float value = 0)**
|
||||
- **void setTableSpoons(float value = 0)**
|
||||
- **void setTeaSpoons(float value = 0)**
|
||||
|
||||
#### Adders
|
||||
|
||||
- **void addLiters(float value = 0)**
|
||||
- **void addMilliLiters(float value = 0)**
|
||||
- **void addCubicMeters(float value = 0)**
|
||||
- **void addLongTons(float value = 0)**
|
||||
- **void addShortTons(float value = 0)**
|
||||
- **void addBarrels(float value = 0)**
|
||||
- **void addGallons(float value = 0)**
|
||||
- **void addQuarts(float value = 0)**
|
||||
- **void addPints(float value = 0)**
|
||||
- **void addCups(float value = 0)**
|
||||
- **void addFluidOunces(float value = 0)**
|
||||
- **void addTableSpoons(float value = 0)**
|
||||
- **void addTeaSpoons(float value = 0)**
|
||||
|
||||
#### getters
|
||||
|
||||
- **float getLiters()**
|
||||
- **float getMilliLiters()**
|
||||
- **float getCubicMeters()**
|
||||
- **float getLongTons()**
|
||||
- **float getShortTons()**
|
||||
- **float getBarrels()**
|
||||
- **float getGallons()**
|
||||
- **float getQuarts()**
|
||||
- **float getPints()**
|
||||
- **float getCups()**
|
||||
- **float getFluidOunces()**
|
||||
- **float getTableSpoons()**
|
||||
- **float getTeaSpoons()**
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
|
||||
#### Should
|
||||
|
||||
- consider using double instead of float.
|
||||
|
||||
#### Could
|
||||
|
||||
- add more unit tests
|
||||
- add more examples
|
||||
|
||||
#### won't (unless)
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
79
libraries/VolumeConverter/VolumeConverter.h
Normal file
79
libraries/VolumeConverter/VolumeConverter.h
Normal file
@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: VolumeConverter.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library to convert volume units.
|
||||
// URL: https://github.com/RobTillaart/VolumeConverter
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define VOLUMECONVERTER_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// VOLUME CONVERTER CLASS
|
||||
//
|
||||
class VolumeConverter
|
||||
{
|
||||
public:
|
||||
VolumeConverter() { _v = 0; };
|
||||
|
||||
// SETTERS
|
||||
void setLiters(float value = 0) { _v = value; };
|
||||
void setMilliLiters(float value = 0) { _v = value * 0.001; };
|
||||
void setCubicMeters(float value = 0) { _v = value * 1000; };
|
||||
void setLongTons(float value = 0) { _v = value * 1284.16209; };
|
||||
void setShortTons(float value = 0) { _v = value * 906.98184; };
|
||||
void setBarrels(float value = 0) { _v = value * 158.9868; };
|
||||
void setGallons(float value = 0) { _v = value * 3.7854; };
|
||||
void setQuarts(float value = 0) { _v = value * 0.94635296; };
|
||||
void setPints(float value = 0) { _v = value * 0.47317648; };
|
||||
void setCups(float value = 0) { _v = value * 0.23658824; };
|
||||
void setFluidOunces(float value = 0) { _v = value * 0.02957353; };
|
||||
void setTableSpoons(float value = 0) { _v = value * 0.01478677; };
|
||||
void setTeaSpoons(float value = 0) { _v = value * 0.00492892; };
|
||||
|
||||
|
||||
// ADDERS
|
||||
void addLiters(float value = 0) { _v += value; };
|
||||
void addMilliLiters(float value = 0) { _v += value * 0.001; };
|
||||
void addCubicMeters(float value = 0) { _v += value * 1000; };
|
||||
void addLongTons(float value = 0) { _v += value * 1284.16209; };
|
||||
void addShortTons(float value = 0) { _v += value * 906.98184; };
|
||||
void addBarrels(float value = 0) { _v += value * 158.9868; };
|
||||
void addGallons(float value = 0) { _v += value * 3.7854; };
|
||||
void addQuarts(float value = 0) { _v += value * 0.94635296; };
|
||||
void addPints(float value = 0) { _v += value * 0.47317648; };
|
||||
void addCups(float value = 0) { _v += value * 0.23658824; };
|
||||
void addFluidOunces(float value = 0) { _v += value * 0.02957353; };
|
||||
void addTableSpoons(float value = 0) { _v += value * 0.01478677; };
|
||||
void addTeaSpoons(float value = 0) { _v += value * 0.00492892; };
|
||||
|
||||
|
||||
// GETTERS
|
||||
float getLiters() { return _v; };
|
||||
float getMilliLiters() { return _v * 1000; };
|
||||
float getCubicMeters() { return _v * 0.001; };
|
||||
float getLongTons() { return _v * (1.0 / 1284.16209); };
|
||||
float getShortTons() { return _v * (1.0 / 906.98184); };
|
||||
float getBarrels() { return _v * (1.0 / 158.9868); };
|
||||
float getGallons() { return _v * (1.0 / 3.7854); };
|
||||
float getQuarts() { return _v * (1.0 / 0.94635296); };
|
||||
float getPints() { return _v * (1.0 / 0.47317648); };
|
||||
float getCups() { return _v * (1.0 / 0.23658824); };
|
||||
float getFluidOunces() { return _v * (1.0 / 0.02957353); };
|
||||
float getTableSpoons() { return _v * (1.0 / 0.01478677); };
|
||||
float getTeaSpoons() { return _v * (1.0 / 0.00492892); };
|
||||
|
||||
|
||||
private:
|
||||
float _v; // liters
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,71 @@
|
||||
//
|
||||
// FILE: volumeConverter_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// DATE: 2022-12-05
|
||||
|
||||
|
||||
#include "VolumeConverter.h"
|
||||
|
||||
VolumeConverter VC;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("VOLUMECONVERTER_LIB_VERSION: ");
|
||||
Serial.println(VOLUMECONVERTER_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
convert(100);
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
float n = random(1000000) * 0.001;
|
||||
convert(n);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void convert(float n)
|
||||
{
|
||||
VC.setLiters(n);
|
||||
|
||||
Serial.print("liters:\t\t");
|
||||
Serial.println(VC.getLiters(), 4);
|
||||
Serial.print("milliLiters:\t");
|
||||
Serial.println(VC.getMilliLiters(), 4);
|
||||
Serial.print("cubic meter:\t");
|
||||
Serial.println(VC.getCubicMeters(), 4);
|
||||
Serial.print("long ton:\t");
|
||||
Serial.println(VC.getLongTons(), 4);
|
||||
Serial.print("short ton:\t");
|
||||
Serial.println(VC.getShortTons(), 4);
|
||||
Serial.print("barrels:\t");
|
||||
Serial.println(VC.getBarrels(), 4);
|
||||
Serial.print("gallons:\t");
|
||||
Serial.println(VC.getGallons(), 4);
|
||||
Serial.print("quarts:\t\t");
|
||||
Serial.println(VC.getQuarts(), 4);
|
||||
Serial.print("pints:\t\t");
|
||||
Serial.println(VC.getPints(), 4);
|
||||
Serial.print("cups:\t\t");
|
||||
Serial.println(VC.getCups(), 4);
|
||||
Serial.print("fluid ounce:\t");
|
||||
Serial.println(VC.getFluidOunces(), 4);
|
||||
Serial.print("table spoons:\t");
|
||||
Serial.println(VC.getTableSpoons(), 4);
|
||||
Serial.print("tea spoons:\t");
|
||||
Serial.println(VC.getTeaSpoons(), 4);
|
||||
|
||||
Serial.println("\n");
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
58
libraries/VolumeConverter/keywords.txt
Normal file
58
libraries/VolumeConverter/keywords.txt
Normal file
@ -0,0 +1,58 @@
|
||||
# Syntax Colouring Map For VolumeConverter
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
VolumeConverter KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
|
||||
setLiters KEYWORD2
|
||||
setMilliLiters KEYWORD2
|
||||
setCubicMeters KEYWORD2
|
||||
setLongTons KEYWORD2
|
||||
setShortTons KEYWORD2
|
||||
setBarrels KEYWORD2
|
||||
setGallons KEYWORD2
|
||||
setQuarts KEYWORD2
|
||||
setPints KEYWORD2
|
||||
setCups KEYWORD2
|
||||
setFluidOunces KEYWORD2
|
||||
setTableSpoons KEYWORD2
|
||||
setTeaSpoons KEYWORD2
|
||||
|
||||
addLiters KEYWORD2
|
||||
addMilliLiters KEYWORD2
|
||||
addCubicMeters KEYWORD2
|
||||
addLongTons KEYWORD2
|
||||
addShortTons KEYWORD2
|
||||
addBarrels KEYWORD2
|
||||
addGallons KEYWORD2
|
||||
addQuarts KEYWORD2
|
||||
addPints KEYWORD2
|
||||
addCups KEYWORD2
|
||||
addFluidOunces KEYWORD2
|
||||
addTableSpoons KEYWORD2
|
||||
addTeaSpoons KEYWORD2
|
||||
|
||||
getLiters KEYWORD2
|
||||
getLiters KEYWORD2
|
||||
getMilliLiters KEYWORD2
|
||||
getCubicMeters KEYWORD2
|
||||
getLongTons KEYWORD2
|
||||
getShortTons KEYWORD2
|
||||
getBarrels KEYWORD2
|
||||
getGallons KEYWORD2
|
||||
getQuarts KEYWORD2
|
||||
getPints KEYWORD2
|
||||
getCups KEYWORD2
|
||||
getFluidOunces KEYWORD2
|
||||
getTableSpoons KEYWORD2
|
||||
getTeaSpoons KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
VOLUME_LIB_VERSION LITERAL1
|
||||
|
23
libraries/VolumeConverter/library.json
Normal file
23
libraries/VolumeConverter/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "VolumeConverter",
|
||||
"keywords": "liter,ton,barrel,gallon,quart,pint,cup,tablespoon,teaspoon",
|
||||
"description": "Arduino library to convert volume units.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/VolumeConverter.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "VolumeConverter.h"
|
||||
}
|
11
libraries/VolumeConverter/library.properties
Normal file
11
libraries/VolumeConverter/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=VolumeConverter
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to convert volume units.
|
||||
paragraph=liter,ton,barrel,gallon,Quart,pint,cup,tablespoon,teaspoon
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/VolumeConverter
|
||||
architectures=*
|
||||
includes=VolumeConverter.h
|
||||
depends=
|
130
libraries/VolumeConverter/test/unit_test_001.cpp
Normal file
130
libraries/VolumeConverter/test/unit_test_001.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-08-29
|
||||
// PURPOSE: unit tests for VolumeConverter class
|
||||
// https://github.com/RobTillaart/VolumeConverter
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual); // a == b
|
||||
// assertNotEqual(unwanted, actual); // a != b
|
||||
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||
// assertLess(upperBound, actual); // a < b
|
||||
// assertMore(lowerBound, actual); // a > b
|
||||
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||
// assertTrue(actual);
|
||||
// assertFalse(actual);
|
||||
// assertNull(actual);
|
||||
|
||||
// // special cases for floats
|
||||
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||
// assertInfinity(actual); // isinf(a)
|
||||
// assertNotInfinity(actual); // !isinf(a)
|
||||
// assertNAN(arg); // isnan(a)
|
||||
// assertNotNAN(arg); // !isnan(a)
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "VolumeConverter.h"
|
||||
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "VOLUMECONVERTER_LIB_VERSION: %s\n", (char *) VOLUMECONVERTER_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
unittest(test_VolumeConverter)
|
||||
{
|
||||
VolumeConverter VC;
|
||||
|
||||
fprintf(stderr, "setLiters\n");
|
||||
VC.setLiters(1);
|
||||
assertEqualFloat(1, VC.getLiters(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setMilliLiters\n");
|
||||
VC.setMilliLiters(1);
|
||||
assertEqualFloat(1, VC.getMilliLiters(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setCubicMeters\n");
|
||||
VC.setCubicMeters(1);
|
||||
assertEqualFloat(1, VC.getCubicMeters(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setLongTons\n");
|
||||
VC.setLongTons(1);
|
||||
assertEqualFloat(1, VC.getLongTons(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setShortTons\n");
|
||||
VC.setShortTons(1);
|
||||
assertEqualFloat(1, VC.getShortTons(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setBarrels\n");
|
||||
VC.setBarrels(1);
|
||||
assertEqualFloat(1, VC.getBarrels(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setGallons\n");
|
||||
VC.setGallons(1);
|
||||
assertEqualFloat(1, VC.getGallons(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setQuarts\n");
|
||||
VC.setQuarts(1);
|
||||
assertEqualFloat(1, VC.getQuarts(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setPints\n");
|
||||
VC.setPints(1);
|
||||
assertEqualFloat(1, VC.getPints(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setCups\n");
|
||||
VC.setCups(1);
|
||||
assertEqualFloat(1, VC.getCups(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setFluidOunces\n");
|
||||
VC.setFluidOunces(1);
|
||||
assertEqualFloat(1, VC.getFluidOunces(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setTableSpoons\n");
|
||||
VC.setTableSpoons(1);
|
||||
assertEqualFloat(1, VC.getTableSpoons(), 0.0001);
|
||||
|
||||
fprintf(stderr, "setTeaSpoons\n");
|
||||
VC.setTeaSpoons(1);
|
||||
assertEqualFloat(1, VC.getTeaSpoons(), 0.0001);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_Gallons)
|
||||
{
|
||||
VolumeConverter VC;
|
||||
|
||||
VC.setGallons(1);
|
||||
assertEqualFloat(1, VC.getGallons(), 0.0001);
|
||||
assertEqualFloat(4, VC.getQuarts(), 0.0001);
|
||||
assertEqualFloat(8, VC.getPints(), 0.0001);
|
||||
assertEqualFloat(16, VC.getCups(), 0.0001);
|
||||
assertEqualFloat(128, VC.getFluidOunces(), 0.001);
|
||||
assertEqualFloat(256, VC.getTableSpoons(), 0.001);
|
||||
assertEqualFloat(768, VC.getTeaSpoons(), 0.003);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user