Skip to content
Open
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
23 changes: 22 additions & 1 deletion proJect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>


<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> <!-- если используете XML-конфиг -->
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions proJect/src/main/java/anlov/java/Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package anlov.java;

public class Factorial {

public static long getFactorial(int num) {
long factorial = 1;
if (num < 0) {
throw new IllegalArgumentException("Число должно быть положительным");
}
for (int i = 1; i <= num; i++) {
factorial *= i;
}
return factorial;
}
}
36 changes: 36 additions & 0 deletions proJect/src/test/java/FactorialTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import anlov.java.Factorial;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class FactorialTests {

@Test
void factorialOfZeroShouldBeOne() {
assertEquals(Factorial.getFactorial(0), 1, "Факториал нуля равен 1");
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void negativeInputShouldThrowException() {
Factorial.getFactorial(-1);
}

@DataProvider(name = "factorialData")
public Object[][] provideFactorialData() {
return new Object[][]{
{0, 1},
{1, 1},
{2, 2},
{3, 6},
{5, 120},
{7, 5040}
};
}

@Test(dataProvider = "factorialData")
public void testFactorial(int input, int expected) {
assertEquals(Factorial.getFactorial(input), expected);
}

}