folks, the method below would throw an Exception if other character than "01xX \t"(including whitespace and \t inside a passed String) is found. If I have this String "1 x \tX 00", the method should return [1,X,X,X,X,X,X,X,0,0] but Im getting only [1,X,X,0,0] in which the 'whitespace' and '\t' somehow are not getting included. 'Whitespace' and '\n' also should return 'X'. Please could smb help me?
//Here's the test case that I'm failing @Test (timeout=3000) public void signal13(){ String inp = "1 x \tX 00"; List<Signal> expecteds = Signal.fromString(inp); assertEquals(expecteds, Arrays.asList(new Signal[]{Signal.HI, Signal.X, Signal.X, Signal.LO, Signal.LO})); } import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public enum Signal { HI, LO, X; public Signal invert() { if(this == HI) return LO; else if(this == LO) return HI; else if(this == X) return X; return this; } public static Signal fromString(char c) { if(c == '1') return HI; else if(c == '0') return LO; else if(c == 'X') return X; else if(c == 'x') return X; else throw new ExceptionLogicMalformedSignal(c, "Invalid character!"); } public static List <Signal> fromString(String inps) { List<Signal> values = new ArrayList<Signal>(); for(int i = 0; i < inps.length(); i++) { if(inps.charAt(i) == '1') values.add(HI); else if(inps.charAt(i) == '0') values.add(LO); else if(inps.charAt(i) == 'X') values.add(X); else if(inps.charAt(i) == 'x') values.add(X); else if(inps.charAt(i) == ' ') values.add(X); else if(inps.charAt(i) == '\t') { values.add(X); values.add(X); } else throw new ExceptionLogicMalformedSignal(inps.charAt(0), "Invalid character!"); } return values; } @Override public String toString() { if(this == HI) return "1"; else if(this == LO) return "0"; else if(this == X) return "X"; return "Error here!"; } public static String toString(List<Signal> sig) { String result = ""; ArrayList<Signal> temp = new ArrayList<>(); for(Signal x: sig) { temp.add(x); } for(int i = 0; i < temp.size(); i++) { if(temp.get(i) == HI) result += "1"; else if(temp.get(i) == LO) result += "0"; else if(temp.get(i) == X) result += "X"; } return result; } }