diff --git a/app/lib/sequence_validator/sequence_validator.dart b/app/lib/sequence_validator/sequence_validator.dart index 84ef4ac..fb557cf 100644 --- a/app/lib/sequence_validator/sequence_validator.dart +++ b/app/lib/sequence_validator/sequence_validator.dart @@ -233,7 +233,7 @@ class SequenceValidator { var completer = _endValidator = Completer(); Future.delayed(const Duration(milliseconds: _smallDiff)) .then((_) { - if (completer.isCompleted) { + if (!completer.isCompleted) { completer.complete(true); } }); diff --git a/app/test/sequence_validator_test.dart b/app/test/sequence_validator_test.dart index e3b2f12..281329b 100644 --- a/app/test/sequence_validator_test.dart +++ b/app/test/sequence_validator_test.dart @@ -1,145 +1,3 @@ -/* -package com.tekartik.utils.sequence; - -import android.annotation.SuppressLint; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import static java.lang.Boolean.TRUE; - -/** - * Created by alex on 23/05/16. - *

- * Basic tap pattern recognition - */ -public abstract class SequenceValidator { - - int sequenceIndex = 0; - private long lastTime = 0; - - static private boolean smallDiff(long diff) { - return diff <= 500; - } - - // Ok in Multi, not ok in Suite for small group - static private boolean mediumDiff(long diff) { - return diff <= 1000; - } - - // True if at least 500ms - static private boolean largeDiff(long diff) { - return diff >= 500 && diff < 3000; - } - - protected abstract boolean validate(long timestamp, long diff); - - public boolean validate(long timestamp) { - long diff = timestamp - lastTime; - if (diff > 1500) { - sequenceIndex = 0; - } - - boolean validated = validate(timestamp, diff); - lastTime = timestamp; - return validated; - } - - @SuppressWarnings("unused") - public boolean validate() { - return validate(System.currentTimeMillis()); - } - - static public class Multi extends SequenceValidator { - - static final int DEFAULT_MULTI_COUNT = 6; - - private final int multiCount; // Default multi count - - public Multi() { - this(DEFAULT_MULTI_COUNT); - } - - public Multi(int multiCount) { - this.multiCount = multiCount; - } - - @Override - protected boolean validate(long timestamp, long diff) { - if (sequenceIndex == 0) { - sequenceIndex = 1; - } else { - if (mediumDiff(diff)) { - sequenceIndex++; - } else { - sequenceIndex = 1; - } - } - if (sequenceIndex == multiCount) { - return true; - } - return false; - } - - - } - - static public class Suite extends SequenceValidator { - - static final List SUITE_LIST_DEFAUT = Arrays.asList(2, 3, 1); - private final List list; - private final int sequenceCount; - @SuppressLint("UseSparseArrays") - private final HashMap sequenceDiffs = new HashMap<>(); - - - public Suite() { - this(SUITE_LIST_DEFAUT); - } - - public Suite(List list) { - this.list = list; - int index = 0; - for (int count : list) { - // for the first allow any - index++; - for (int i = 1; i < count; i++) { - // requires small diff then - sequenceDiffs.put(index++, true); - } - } - sequenceCount = index; - } - - @Override - protected boolean validate(long timestamp, long diff) { - if (sequenceIndex == 0) { - sequenceIndex = 1; - } else { - Boolean checkSmallDiff = sequenceDiffs.get(sequenceIndex); - if (TRUE.equals(checkSmallDiff)) { - if (SequenceValidator.smallDiff(diff)) { - sequenceIndex++; - } else { - sequenceIndex = 1; - } - } else if (SequenceValidator.largeDiff(diff)) { - sequenceIndex++; - } else { - sequenceIndex = 1; - } - } - if (sequenceIndex == sequenceCount) { - return true; - } - return false; - } - } - -} - - */ import 'dart:async'; import 'package:tekartik_app_common_utils/sequence_validator/sequence_validator.dart'; diff --git a/app_csv/test/app_csv_test.dart b/app_csv/test/app_csv_test.dart index bb58274..5d5dd8f 100644 --- a/app_csv/test/app_csv_test.dart +++ b/app_csv/test/app_csv_test.dart @@ -180,11 +180,10 @@ int,double,String,bool,Uint8List ]); }); test('test_quotes', () async { - var csv = - '''Id question,Question FR,Question EN,Resp.A. FR,Resp.A. EN,Resp.B. FR,Resp.B. EN,Resp.C. FR,Resp.C EN,Bonne réponse -2,Quel joueur détient le record du nombre d'essais marqués en Coupe du monde de rugby ?,Which player holds the record for the most tries scored in the Rugby World Cup?,Bryan Habana,Bryan Habana,Jonah Lomu,Jonah Lomu,Jonny Wilkinson,Jonny Wilkinson,B -4,Dans quel pays se déroule traditionnellement le tournoi des Tri-Nations ?,In which country is the Tri-Nations tournament traditionally held?,"Australie, Nouvelle-Zélande, Afrique du Sud","Australia, New Zealand, South Africa","Angleterre, Ecosse, Pays de Galles","England, Scotland, Wales","Irlande, France, Italie","Ireland, France, Italy",A -5,Quel est le poste d’Antoine Dupont en équipe de France ?,What is Antoine Dupont’s position in the French team?,Centre,Center,Troisième ligne aile,Third line wing,Demi de mêlée,Scrum-half,C + var csv = '''I,Qf,Ae,Raf,Rae,Rbf,Rbe,Rcf,Rce,B +2,d'e,t,B,B,J,J,J,J,B +4,p,c,"A","A","A","E","I","I",A +5,d’A,t’s,C,C,T,T,D,S,C '''; var converter = CsvToListConverter( csvSettingsDetector: FirstOccurrenceSettingsDetector(eols: [ @@ -194,7 +193,42 @@ int,double,String,bool,Uint8List '"', ])); expect(csvToMapList(csv, converter: converter), [ - {'a': 1, 'b': '2,3'} + { + 'I': 2, + 'Qf': 'd\'e', + 'Ae': 't', + 'Raf': 'B', + 'Rae': 'B', + 'Rbf': 'J', + 'Rbe': 'J', + 'Rcf': 'J', + 'Rce': 'J', + 'B': 'B' + }, + { + 'I': 4, + 'Qf': 'p', + 'Ae': 'c', + 'Raf': 'A', + 'Rae': 'A', + 'Rbf': 'A', + 'Rbe': 'E', + 'Rcf': 'I', + 'Rce': 'I', + 'B': 'A' + }, + { + 'I': 5, + 'Qf': 'd’A', + 'Ae': 't’s', + 'Raf': 'C', + 'Rae': 'C', + 'Rbf': 'T', + 'Rbe': 'T', + 'Rcf': 'D', + 'Rce': 'S', + 'B': 'C' + } ]); }); test('separator', () {