Fail PrintingTest printStarsTest1 (#Exercise 39.1)

2,514 views
Skip to first unread message

bishesh acharya

unread,
May 29, 2016, 5:07:05 AM5/29/16
to moo...@googlegroups.com
My code:
public class Printing {

    public static void printStars(int amount) {
        //
    }

    public static void printSquare(int sideSize) {
        //
    }

    public static void printRectangle(int width, int height) {
        //
    }

    public static void printTriangle(int size) {
        //
    }

    public static void main(String[] args) {
        // Tests do not use main, yo can write code here freely!
        // if you have problems with tests, please try out first
        // here to see that the printout looks correct
        printStars(5);
        printStars(3);
        printStars(9);
        System.out.println(" ---");  // printing --- to separate the figures
        printSquare(4);
        System.out.println(" ---");
        printRectangle(5,6);
        System.out.println(" ---");
        printTriangle(3);
        System.out.println(" ---");
    }
  
}

Error:

java.lang.AssertionError: You did not print a line break when printStars was called org.junit.Assert.fail(Assert.java:93) org.junit.Assert.assertTrue(Assert.java:43) PrintingTest.printStarsTest1(PrintingTest.java:41) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) org.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:52) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:2014) org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:885) org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:713) org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401) org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:98) org.powermock.classloading.ClassloaderExecutor.execute(ClassloaderExecutor.java:78) org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:49) org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) org.junit.runners.ParentRunner.run(ParentRunner.java:300) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.runTestCase(TestRunner.java:134) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.doRun(TestRunner.java:89) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.run(TestRunner.java:70) java.lang.Thread.run(Thread.java:744)

joni.m...@gmail.com

unread,
Jun 25, 2014, 6:49:02 PM6/25/14
to moo...@googlegroups.com
Hey,

Error says that method printStars must print line break after printing the stars, so simply writing System.out.println(); to the end of printStars method, that problem should then be fixed. But you also need to remove extra line breaks from your other methods.

Best regards,
Joni


keskiviikko, 21. toukokuuta 2014 14.12.03 UTC+3 bishesh acharya kirjoitti:
My code:
public class Printing {

    public static void printStars(int amount) {
        // 39.1
        // you can print one star with the command
        for(int i=1;i<=amount;i++){
        System.out.print("*");
        // call this command amount times

        }
    }

    public static void printSquare(int sideSize) {
        // 39.2
        int i = 1;
        while(i<=sideSize){
        printStars(sideSize);
        System.out.print("\n");
        i++;

        }
    }

    public static void printRectangle(int width, int height) {
        // 39.3
        for(int i=1;i<=height;i++){
        printStars(width);
            System.out.print("\n");

        }
       
    }

    public static void printTriangle(int size) {
        // 39.4
        for(int i=1;i <= size;i++){
        printStars(i);
        System.out.print("\n");
Message has been deleted

nathanael...@gmail.com

unread,
Aug 29, 2017, 1:31:44 AM8/29/17
to mooc.fi
Thank you, I had System.out.println(""); in every method call and kept getting 90% but doing it your way got me the correct solution and made the code much more intuitive

gkuk...@gmail.com

unread,
Sep 1, 2019, 6:59:50 AM9/1/19
to mooc.fi
I was adding `System.out.print("\n");` but it was expecting `System.out.println();`, and it took me two hours to figure it out. 😁 😂😛🤓

I too, getting 90% test ok by adding line break in all others methods, finally solved. 😁 😂
Reply all
Reply to author
Forward
0 new messages