Results 1 to 11 of 11

Thread: Other Test?!

  1. #1
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Other Test?!

    This is Problem : Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that the remove string is length 1 or more. Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".

    withoutString("Hello there", "llo") → "He there"
    withoutString("Hello there", "e") → "Hllo thr"
    withoutString("Hello there", "x") → "Hello there"

    =====================
    and this is my answer :
    Java Code:
    public String withoutString(String base, String remove) {  
    		String r = remove.toLowerCase() ;
    		String b = remove.toUpperCase();
    		String res = "";
    		for(int i=0;i<base.length();i++){
    			int v = base.indexOf(r,i);
    			if(v<0) {
    				res+= base.substring(i, base.length());
    				break;
    			}else{
    			res += base.substring(i,v);
    			}
    			i = v+r.length()-1;
    		}
    		String fres = res;
    		String rr="";
    		for(int z=0;z<fres.length();z++){
    			int g = fres.indexOf(b,z);
    			if(g<0){
    				rr += fres.substring(z, fres.length());
    				break;
    			}else{
    				rr += fres.substring(z, g);
    			}
    			z = g+b.length()-1;
    		}
    		return rr;		
    	}
    ====================
    and this is results :
    withoutString("Hello there", "llo") → "He there" "He there" OK
    withoutString("Hello there", "e") → "Hllo thr" "Hllo thr" OK
    withoutString("Hello there", "x") → "Hello there" "Hello there" OK
    withoutString("This is a FISH", "IS") → "Th a FH" "Th a FH" OK
    withoutString("THIS is a FISH", "is") → "TH a FH" "TH a FH" OK
    withoutString("THIS is a FISH", "iS") → "TH a FH" "TH a FH" OK
    withoutString("abxxxxab", "xx") → "abab" "abab" OK
    withoutString("abxxxab", "xx") → "abxab" "abxab" OK
    withoutString("abxxxab", "x") → "abab" "abab" OK
    withoutString("xxx", "x") → "" "" OK
    withoutString("xxx", "xx") → "x" "x" OK
    withoutString("xyzzy", "Y") → "xzz" "xzz" OK
    withoutString("", "x") → "" "" OK
    withoutString("abcabc", "b") → "acac" "acac" OK
    other tests X

    =======================
    it say other tests are wrong ! what can be other tests?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    it say other tests are wrong !
    What program generates that message?
    What are the Strings it passes to your code?

  3. #3
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default

    i solve problems of codingbat and this problem is this:
    http://codingbat.com/prob/p192570
    Last edited by HearT.Hunt3r; 08-28-2011 at 01:15 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Can you add printlns to print out what Strings are passed to your code that you are not correctly processing?

    How do you know that the output from the testing program is correct?

  5. #5
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default

    this site has a compiler that do the same job... and i checked my answers and they was correct.
    i haven't other tests! and i wanna know that what example don't work with my code!

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    i wanna know that what example don't work with my code!
    Why do you think anyone here would know?

  7. #7
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default

    because i asked a question before and one person knew that... anyway thx.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Have you tried making your own testing driver and given it every possible combination of inputs and checked that the output is correct?

  9. #9
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default

    no i didn't

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    That would be one way to find the problem in your program.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    From the help page on that site:

    There may be a few "other tests" listed at the bottom of the table but which are not detailed -- these additional tests are similar to the ones shown in the table, but with different numbers, strings, etc. filled in.
    Reading helps ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Is it possible to test for NaN?
    By AJArmstron@aol.com in forum New To Java
    Replies: 7
    Last Post: 05-07-2010, 02:22 AM
  2. Replies: 0
    Last Post: 04-05-2008, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •