Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart3a #40

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/sequence_validator/sequence_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class SequenceValidator {
var completer = _endValidator = Completer<bool>();
Future<void>.delayed(const Duration(milliseconds: _smallDiff))
.then((_) {
if (completer.isCompleted) {
if (!completer.isCompleted) {
completer.complete(true);
}
});
Expand Down
142 changes: 0 additions & 142 deletions app/test/sequence_validator_test.dart
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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<Integer> SUITE_LIST_DEFAUT = Arrays.asList(2, 3, 1);
private final List<Integer> list;
private final int sequenceCount;
@SuppressLint("UseSparseArrays")
private final HashMap<Integer, Boolean> sequenceDiffs = new HashMap<>();


public Suite() {
this(SUITE_LIST_DEFAUT);
}

public Suite(List<Integer> 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';
Expand Down
46 changes: 40 additions & 6 deletions app_csv/test/app_csv_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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', () {
Expand Down