-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for SortBy, SortType and DirSortBy
- Loading branch information
Showing
3 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/src/test/java/com/amaze/filemanager/filesystem/files/sort/DirSortByTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2014-2023 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>, | ||
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors. | ||
* | ||
* This file is part of Amaze File Manager. | ||
* | ||
* Amaze File Manager is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.amaze.filemanager.filesystem.files.sort | ||
|
||
import android.os.Build | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.amaze.filemanager.shadows.ShadowMultiDex | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import kotlin.random.Random | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config( | ||
shadows = [ShadowMultiDex::class], | ||
sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.P, Build.VERSION_CODES.R] | ||
) | ||
class DirSortByTest { | ||
/** Tests if [DirSortBy.getDirSortBy] returns the correct [DirSortBy] corresponding to the given index */ | ||
@Test | ||
fun getDirSortByTest() { | ||
Assert.assertEquals("DirSortBy.getDirSortBy(0) did not return DIR_ON_TOP", DirSortBy.DIR_ON_TOP, DirSortBy.getDirSortBy(0)) | ||
Assert.assertEquals("DirSortBy.getDirSortBy(1) did not return FILE_ON_TOP", DirSortBy.FILE_ON_TOP, DirSortBy.getDirSortBy(1)) | ||
Assert.assertEquals("DirSortBy.getDirSortBy(2) did not return NONE_ON_TOP", DirSortBy.NONE_ON_TOP, DirSortBy.getDirSortBy(2)) | ||
// could be any int except 0 to 2 | ||
val randomIndex = Random.nextInt(3, Int.MAX_VALUE) | ||
Assert.assertEquals("DirSortBy.getDirSortBy(${randomIndex}) did not return NONE_ON_TOP", DirSortBy.NONE_ON_TOP, DirSortBy.getDirSortBy(randomIndex)) | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
app/src/test/java/com/amaze/filemanager/filesystem/files/sort/SortByTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (C) 2014-2023 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>, | ||
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors. | ||
* | ||
* This file is part of Amaze File Manager. | ||
* | ||
* Amaze File Manager is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.amaze.filemanager.filesystem.files.sort | ||
|
||
import android.os.Build | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.amaze.filemanager.shadows.ShadowMultiDex | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import kotlin.random.Random | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config( | ||
shadows = [ShadowMultiDex::class], | ||
sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.P, Build.VERSION_CODES.R] | ||
) | ||
class SortByTest { | ||
|
||
/** Tests if [SortBy.getSortBy] returns the correct [SortBy] corresponding to the given index */ | ||
@Test | ||
fun getSortByTest() { | ||
Assert.assertEquals( | ||
"SortBy.getSortBy(0) did not return NAME", | ||
SortBy.NAME, | ||
SortBy.getSortBy(0) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getSortBy(1) did not return LAST_MODIFIED", | ||
SortBy.LAST_MODIFIED, | ||
SortBy.getSortBy(1) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getSortBy(2) did not return SIZE", | ||
SortBy.SIZE, | ||
SortBy.getSortBy(2) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getSortBy(3) did not return TYPE", | ||
SortBy.TYPE, | ||
SortBy.getSortBy(3) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getSortBy(4) did not return RELEVANCE", | ||
SortBy.RELEVANCE, | ||
SortBy.getSortBy(4) | ||
) | ||
// could be any int except 0 to 4 | ||
val randomIndex = Random.nextInt(5, Int.MAX_VALUE) | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy($randomIndex) did not return NAME", | ||
SortBy.NAME, | ||
SortBy.getDirectorySortBy(randomIndex) | ||
) | ||
} | ||
|
||
/** Tests if [SortBy.getDirectorySortBy] returns the correct [SortBy] corresponding to the given index */ | ||
@Test | ||
fun getDirectorySortByTest() { | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy(0) did not return NAME", | ||
SortBy.NAME, | ||
SortBy.getDirectorySortBy(0) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy(1) did not return LAST_MODIFIED", | ||
SortBy.LAST_MODIFIED, | ||
SortBy.getDirectorySortBy(1) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy(2) did not return SIZE", | ||
SortBy.SIZE, | ||
SortBy.getDirectorySortBy(2) | ||
) | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy(3) did not return TYPE", | ||
SortBy.TYPE, | ||
SortBy.getDirectorySortBy(3) | ||
) | ||
// could be any int except 0 to 3 | ||
val randomIndex = Random.nextInt(4, Int.MAX_VALUE) | ||
Assert.assertEquals( | ||
"SortBy.getDirectorySortBy($randomIndex) did not return NAME", | ||
SortBy.NAME, | ||
SortBy.getDirectorySortBy(randomIndex) | ||
) | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
app/src/test/java/com/amaze/filemanager/filesystem/files/sort/SortTypeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (C) 2014-2023 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>, | ||
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors. | ||
* | ||
* This file is part of Amaze File Manager. | ||
* | ||
* Amaze File Manager is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.amaze.filemanager.filesystem.files.sort | ||
|
||
import android.os.Build | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.amaze.filemanager.shadows.ShadowMultiDex | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config( | ||
shadows = [ShadowMultiDex::class], | ||
sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.P, Build.VERSION_CODES.R] | ||
) | ||
class SortTypeTest { | ||
|
||
/** Tests if the Int returned from [SortType.toDirectorySortInt] is as expected */ | ||
@Test | ||
fun toDirectorySortIntTest() { | ||
Assert.assertEquals( | ||
"SortType with SortBy.NAME and SortOrder.ASC was not 0", | ||
0, | ||
SortType(SortBy.NAME, SortOrder.ASC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.LAST_MODIFIED and SortOrder.ASC was not 1", | ||
1, | ||
SortType(SortBy.LAST_MODIFIED, SortOrder.ASC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.SIZE and SortOrder.ASC was not 2", | ||
2, | ||
SortType(SortBy.SIZE, SortOrder.ASC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.TYPE and SortOrder.ASC was not 3", | ||
3, | ||
SortType(SortBy.TYPE, SortOrder.ASC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.NAME and SortOrder.DESC was not 4", | ||
4, | ||
SortType(SortBy.NAME, SortOrder.DESC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.LAST_MODIFIED and SortOrder.DESC was not 5", | ||
5, | ||
SortType(SortBy.LAST_MODIFIED, SortOrder.DESC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.SIZE and SortOrder.DESC was not 6", | ||
6, | ||
SortType(SortBy.SIZE, SortOrder.DESC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.TYPE and SortOrder.DESC was not 7", | ||
7, | ||
SortType(SortBy.TYPE, SortOrder.DESC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.RELEVANCE and SortOrder.ASC was not 0", | ||
0, | ||
SortType(SortBy.RELEVANCE, SortOrder.ASC).toDirectorySortInt() | ||
) | ||
Assert.assertEquals( | ||
"SortType with SortBy.RELEVANCE and SortOrder.DESC was not 4", | ||
4, | ||
SortType(SortBy.RELEVANCE, SortOrder.DESC).toDirectorySortInt() | ||
) | ||
} | ||
|
||
/** Tests if the [SortType] returned from [SortType.getDirectorySortType] corresponds to the given index */ | ||
@Test | ||
fun getDirectorySortTypeTest() { | ||
Assert.assertEquals( | ||
"0 was not translated to SortType with SortBy.NAME and SortOrder.ASC", | ||
SortType(SortBy.NAME, SortOrder.ASC), | ||
SortType.getDirectorySortType(0) | ||
) | ||
Assert.assertEquals( | ||
"1 was not translated to SortType with SortBy.LAST_MODIFIED and SortOrder.ASC", | ||
SortType(SortBy.LAST_MODIFIED, SortOrder.ASC), | ||
SortType.getDirectorySortType(1) | ||
) | ||
Assert.assertEquals( | ||
"2 was not translated to SortType with SortBy.SIZE and SortOrder.ASC", | ||
SortType(SortBy.SIZE, SortOrder.ASC), | ||
SortType.getDirectorySortType(2) | ||
) | ||
Assert.assertEquals( | ||
"3 was not translated to SortType with SortBy.TYPE and SortOrder.ASC", | ||
SortType(SortBy.TYPE, SortOrder.ASC), | ||
SortType.getDirectorySortType(3) | ||
) | ||
Assert.assertEquals( | ||
"4 was not translated to SortType with SortBy.NAME and SortOrder.DESC", | ||
SortType(SortBy.NAME, SortOrder.DESC), | ||
SortType.getDirectorySortType(4) | ||
) | ||
Assert.assertEquals( | ||
"5 was not translated to SortType with SortBy.LAST_MODIFIED and SortOrder.DESC", | ||
SortType(SortBy.LAST_MODIFIED, SortOrder.DESC), | ||
SortType.getDirectorySortType(5) | ||
) | ||
Assert.assertEquals( | ||
"6 was not translated to SortType with SortBy.SIZE and SortOrder.DESC", | ||
SortType(SortBy.SIZE, SortOrder.DESC), | ||
SortType.getDirectorySortType(6) | ||
) | ||
Assert.assertEquals( | ||
"7 was not translated to SortType with SortBy.TYPE and SortOrder.DESC", | ||
SortType(SortBy.TYPE, SortOrder.DESC), | ||
SortType.getDirectorySortType(7) | ||
) | ||
} | ||
} |