Premium (8 passadas, R$ 39,90/m, SKU DTFP.TX.100CM) is a fifth textile ready-sheet product: priced on the server and the Site, a hidden fifth card, a PREMIUM hot-folder class, its Tiny SKU, and a products row created disabled by a migration until Dropstar says 'testado'. A machine with no typed minimum now alerts at Dropstar's fixed minimums: 1 roll of film, 1 L of each ink, 5 kg of powder. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
67 lines
3.3 KiB
Python
67 lines
3.3 KiB
Python
"""The machine sheet's pure calculations (Fase 2, front 1a), without a database."""
|
|
import unittest
|
|
from decimal import Decimal
|
|
|
|
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, DEFAULT_MINIMUMS,
|
|
estimate, minimum_for, one_decimal, supply_low)
|
|
|
|
|
|
class EstimateTest(unittest.TestCase):
|
|
def test_two_entries_give_an_estimate(self):
|
|
value = estimate([Decimal('1'), Decimal('2')], [Decimal('10')], Decimal('5'), Decimal('0.5'))
|
|
self.assertEqual(value['per_metre'], Decimal('0.2'))
|
|
self.assertEqual(value['stock'], Decimal('1.0'))
|
|
self.assertEqual(value['metres_left'], Decimal('5'))
|
|
self.assertEqual(value['minimum'], Decimal('0.5'))
|
|
self.assertFalse(supply_low(value))
|
|
|
|
def test_one_entry_has_no_estimate(self):
|
|
self.assertIsNone(estimate([Decimal('1')], [], Decimal('10'), None))
|
|
|
|
def test_an_interval_without_film_has_no_estimate(self):
|
|
self.assertIsNone(estimate([Decimal('1'), Decimal('1')], [Decimal('0')], Decimal('0'), None))
|
|
|
|
def test_the_minimum_reached_is_an_alert(self):
|
|
# 0.1 per metre, one litre refilled on average, nine metres later:
|
|
# 0.1 L left, below the machine's 1.5 L minimum.
|
|
value = estimate([Decimal('1'), Decimal('1')], [Decimal('10')], Decimal('9'), Decimal('1.5'))
|
|
self.assertEqual(value['stock'], Decimal('0.1'))
|
|
self.assertTrue(supply_low(value))
|
|
|
|
def test_only_the_last_intervals_are_averaged(self):
|
|
# Four intervals; SUPPLY_INTERVALS is three, so the 100 m one is ignored.
|
|
value = estimate([Decimal('1'), Decimal('1'), Decimal('3'), Decimal('3'), Decimal('3')],
|
|
[Decimal('100'), Decimal('10'), Decimal('10'), Decimal('10')], Decimal('0'), None)
|
|
self.assertEqual(value['per_metre'], Decimal('0.3'))
|
|
|
|
def test_the_thresholds_are_the_documented_ones(self):
|
|
self.assertEqual(CLEAN_EVERY_METRES, Decimal('10'))
|
|
self.assertEqual(ALIGN_AFTER_FILM_METRES, Decimal('20'))
|
|
|
|
def test_a_machine_without_typed_minimums_alerts_at_dropstars_defaults(self):
|
|
# Marcus, 2026-11-10: 1 roll of film, 1 L of each ink, 5 kg of powder.
|
|
self.assertEqual(DEFAULT_MINIMUMS, {'film': Decimal('1'), 'ink_c': Decimal('1'),
|
|
'ink_m': Decimal('1'), 'ink_y': Decimal('1'),
|
|
'ink_k': Decimal('1'), 'ink_w': Decimal('1'),
|
|
'powder': Decimal('5')})
|
|
for item, default in DEFAULT_MINIMUMS.items():
|
|
with self.subTest(item=item):
|
|
minimum = minimum_for({}, item)
|
|
self.assertEqual(minimum, default)
|
|
value = estimate([Decimal('1'), Decimal('1')], [Decimal('10')],
|
|
Decimal('9'), minimum)
|
|
self.assertTrue(supply_low(value))
|
|
# A minimum Gestão typed still wins over the default.
|
|
self.assertEqual(minimum_for({'film': Decimal('0')}, 'film'), Decimal('0'))
|
|
|
|
|
|
class AlertTextTest(unittest.TestCase):
|
|
def test_one_decimal_uses_a_comma(self):
|
|
self.assertEqual(one_decimal(Decimal('10.44')), '10,4')
|
|
self.assertEqual(one_decimal(Decimal('3')), '3,0')
|
|
self.assertEqual(one_decimal(Decimal('19.86')), '19,9')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|