Skip to content

Commit

Permalink
add tests for SortBy, SortType and DirSortBy
Browse files Browse the repository at this point in the history
  • Loading branch information
seelchen committed Dec 6, 2023
1 parent 8a60a3f commit ce70619
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 0 deletions.
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))
}
}
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)
)
}
}
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)
)
}
}

0 comments on commit ce70619

Please sign in to comment.