From f6cb45b954ade2b3558567da62f358e3ad67f8ba Mon Sep 17 00:00:00 2001 From: Guido Longoni Date: Fri, 27 Sep 2019 14:28:50 +0200 Subject: [PATCH] Esempio filtro test --- MkpWIFI/test_filtro.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 MkpWIFI/test_filtro.py diff --git a/MkpWIFI/test_filtro.py b/MkpWIFI/test_filtro.py new file mode 100644 index 0000000..75ae2f7 --- /dev/null +++ b/MkpWIFI/test_filtro.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Sep 27 11:21:37 2019 + +@author: Guido Longoni - guidolongoni@gmail.com +""" + +regole = [ + (lambda x: isinstance(x, int) and x > 0, 'è un intero positivo'), + (lambda x: isinstance(x, int) and x < 0, 'è un intero negativo'), + (lambda x: isinstance(x, float) and x > 0, 'è un reale positivo'), + (lambda x: isinstance(x, float) and x < 0, 'è un reale negativo'), + (lambda x: True, 'non è un numero'), +] + + +test = [1,-1,'ciao',3.14,-0.5] + +risultato_filtro = [str(dato)+' '+next(regola[1] for regola in regole if regola[0](dato)) for dato in test]