Refactor SupportDialog

This commit is contained in:
Reinhard Pointner 2016-09-20 15:32:50 +08:00
parent 2ef12d936f
commit 0bd6625095
2 changed files with 7 additions and 4 deletions

View File

@ -86,15 +86,17 @@ public enum SupportDialog {
}; };
public boolean feelingLucky(int sessionRenameCount, int totalRenameCount, int currentRevision, int lastSupportRevision, int supportRevisionCount) { public boolean feelingLucky(int sessionRenameCount, int totalRenameCount, int currentRevision, int lastSupportRevision, int supportRevisionCount) {
// ask only once per revision // ask for reviews only once per revision
if (currentRevision <= lastSupportRevision && this == AppStoreReview) { if (currentRevision <= lastSupportRevision && isAppStore()) {
return false; return false;
} }
if (sessionRenameCount >= 2000) { // always lucky if many files are processed in a single session
if (sessionRenameCount >= 2000 * Math.pow(2, supportRevisionCount)) {
return true; return true;
} }
// sometimes lucky if many files have been processed over time
return totalRenameCount >= 1000 * Math.pow(4, supportRevisionCount) && Math.random() >= 0.777; return totalRenameCount >= 1000 * Math.pow(4, supportRevisionCount) && Math.random() >= 0.777;
} }

View File

@ -11,10 +11,11 @@ public class SupportDialogTest {
@Test @Test
public void feelingLucky() { public void feelingLucky() {
assertTrue(SupportDialog.AppStoreReview.feelingLucky(2000, 2000, 500, 400, 0)); assertTrue(SupportDialog.AppStoreReview.feelingLucky(2000, 2000, 500, 400, 0));
assertFalse(SupportDialog.AppStoreReview.feelingLucky(2000, 2000, 400, 400, 0)); assertFalse(SupportDialog.AppStoreReview.feelingLucky(2000, 2000, 400, 400, 1));
assertTrue(SupportDialog.Donation.feelingLucky(2000, 2000, 400, 400, 0)); assertTrue(SupportDialog.Donation.feelingLucky(2000, 2000, 400, 400, 0));
assertFalse(SupportDialog.Donation.feelingLucky(100, 100, 400, 400, 0)); assertFalse(SupportDialog.Donation.feelingLucky(100, 100, 400, 400, 0));
assertFalse(SupportDialog.Donation.feelingLucky(2000, 2000, 400, 400, 1));
assertTrue(IntStream.range(0, 100).anyMatch(i -> SupportDialog.Donation.feelingLucky(0, 5000, 400, 400, 0))); assertTrue(IntStream.range(0, 100).anyMatch(i -> SupportDialog.Donation.feelingLucky(0, 5000, 400, 400, 0)));
assertFalse(IntStream.range(0, 100).anyMatch(i -> SupportDialog.Donation.feelingLucky(0, 5000, 400, 400, 2))); assertFalse(IntStream.range(0, 100).anyMatch(i -> SupportDialog.Donation.feelingLucky(0, 5000, 400, 400, 2)));