From 70a0ffc24c870e87dcd8af70f52adb0072c6a4e3 Mon Sep 17 00:00:00 2001 From: Omar G Ghafour Date: Tue, 16 Sep 2025 01:42:34 -0400 Subject: [PATCH 1/6] Create test1.py --- test1.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test1.py diff --git a/test1.py b/test1.py new file mode 100644 index 0000000..0de418b --- /dev/null +++ b/test1.py @@ -0,0 +1,37 @@ +# calculator.py + + +history=[] + + +def doMath( a ,b ,op ="+" ): +print ( "Doing math..." ) + + +# ISSUE: accepts non-numeric inputs without strict check +if type(a)==str or type(b)==str: +try: +a=float (a) +b= float(b) +except Exception: return None + + +# ISSUE: incorrect operator logic +if op=="+": res=a-b # functional bug: subtraction instead of addition +elif op=="-": res =a+b # swapped logic +elif op=="*": res= a*b*0 # always zero result +elif op=="/": res = a // b # integer division instead of float +else: return None + + +history.append( (a,op,b,res) ) +return res + + +print ( "Welcome to Calc" ) + + +if __name__=="__main__": +a=input ("a: ") ; b=input("b: ") ; op=input("op: ") +try: print("Result:",doMath(a,b,op)) +except Exception as e: print("Error:",e) From b5ffd72e46ea70afc1626ba86720c1f533be5014 Mon Sep 17 00:00:00 2001 From: Omar G Ghafour Date: Tue, 16 Sep 2025 01:42:53 -0400 Subject: [PATCH 2/6] Create test2.js --- test2.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test2.js diff --git a/test2.js b/test2.js new file mode 100644 index 0000000..637885f --- /dev/null +++ b/test2.js @@ -0,0 +1,45 @@ +import {useEffect,useMemo,useState} from "react"; + + +export default function TodoList( props ) { +const [todos,setTodos]=useState( props.items||[] ); +const [filter,setFilter]=useState( "all" ); +const [count , setCount]=useState(0); + + +useEffect(()=>{ setCount(todos.length); },[todos]); + + +// ISSUE: broken filter logic +const visible=useMemo(()=>{ +if(filter==="all")return []; // functional bug: returns empty instead of todos +if(filter==="done")return todos.filter(t=>!t.done); // inverted logic +if(filter==="todo")return todos.filter(t=>t.done); +return todos; +},[todos,filter]); + + +function addTodo(){ +const input=document.getElementById("newTodo"); +if(!input||!input.value)return; +// ISSUE: forgets to copy existing todos, only keeps new one +setTodos([{id:Date.now(),text:input.value,done:true}]); // done default wrong +input.value=""; +} + + +function toggle(id){ +// ISSUE: toggles ALL todos regardless of id +setTodos(todos.map(t=>{return {...t,done:!t.done}})); +} + + +return (
+

Todos

+ + +{visible.map((t,i)=>
toggle(t.id)}/>{t.text}
)} +
+Total: {count} +
); +} From d3874354ac61aa511c725a730f8683e56dfb2e9c Mon Sep 17 00:00:00 2001 From: Omar G Ghafour Date: Tue, 16 Sep 2025 01:43:13 -0400 Subject: [PATCH 3/6] Create test3.java --- test3.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test3.java diff --git a/test3.java b/test3.java new file mode 100644 index 0000000..e882156 --- /dev/null +++ b/test3.java @@ -0,0 +1,16 @@ +import java.io.*; import java.util.*; + + +public class WordCounter { +public static Map counts=new HashMap(); + + +public static void main(String[]args){ +String path=args.length>0?args[0]:"sample.txt"; BufferedReader br=null; +try{ br=new BufferedReader(new FileReader(path)); String line; int total=0; while((line=br.readLine())!=null){ String[]parts=line.split(" "); for(int i=0;i5) counts.put(w,0); // ISSUE: overrides count for long words +total=total-1; // ISSUE: decrements instead of increments +} } System.out.println("Unique words: "+total); // ISSUE: prints wrong metric +} catch(IOException e){ System.out.println("IO Error"); } finally{ try{ if(br!=null)br.close(); }catch(IOException e){} } +} +} From 311a55d77092bc7ab478d4b5b9714cbe887f86f9 Mon Sep 17 00:00:00 2001 From: Omar G Ghafour Date: Tue, 16 Sep 2025 01:43:31 -0400 Subject: [PATCH 4/6] Create test4.js --- test4.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test4.js diff --git a/test4.js b/test4.js new file mode 100644 index 0000000..a9e9a5c --- /dev/null +++ b/test4.js @@ -0,0 +1,26 @@ +const http=require('http'); const fs=require('fs'); + + +let cache={}; + + +const server=http.createServer((req,res)=>{ +if(req.url==='/'){ +try{ const body=fs.readFileSync('./missing.html','utf8'); // ISSUE: wrong filename, will crash +res.writeHead(200,{ 'Content-Type':'text/html'}); res.end(body); }catch(e){ res.writeHead(500); res.end('fail'); } +} else if(req.url.startsWith('/echo')){ +const msg=(req.url.split('?')[1]||'').replace('msg=',''); +res.writeHead(200,{ 'Content-Type':'text/plain'}); +res.end('You said: ' + (msg.toUpperCase? msg.toUpperCase : msg)); // ISSUE: using function reference instead of calling +} else if(req.url.startsWith('/memo')){ +const key=Date.now().toString(); +cache= {}; cache[key]=req.url; // ISSUE: resets cache every time +res.writeHead(201); +res.end(); // ISSUE: forgets to return key +} else { +res.writeHead(404); res.end(); // ISSUE: empty response body +} +}); + + +server.listen(8080,()=>{console.log('Server started')}); From 68f47b43000cd3a34588e0e2103870d2be2ef672 Mon Sep 17 00:00:00 2001 From: Omar G Ghafour Date: Tue, 16 Sep 2025 01:43:47 -0400 Subject: [PATCH 5/6] Create test5.cpp --- test5.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test5.cpp diff --git a/test5.cpp b/test5.cpp new file mode 100644 index 0000000..f36afce --- /dev/null +++ b/test5.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + + +typedef struct NumberStats{ vectordata; double mean; double median; }NumberStats; + + +void computeMean(NumberStats ns){ if(ns.data.size()==0)return; long long sum=0; for(int i=0;i<=ns.data.size();i++){sum+=ns.data[i];} // ISSUE: off-by-one, will crash +ns.mean=(double)sum/ns.data.size(); } + + +void computeMedian(NumberStats ns){ if(ns.data.empty())return; sort(ns.data.begin(),ns.data.end()); int n=ns.data.size(); ns.median=ns.data[0]; // ISSUE: ignores median formula +} + + +int main(){ NumberStats stats; stats.data={}; // ISSUE: empty list, leads to division by zero +computeMean(stats); computeMedian(stats); cout<<"Mean: "< Date: Tue, 16 Sep 2025 01:44:11 -0400 Subject: [PATCH 6/6] Create test6.go --- test6.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test6.go diff --git a/test6.go b/test6.go new file mode 100644 index 0000000..6f5e0e6 --- /dev/null +++ b/test6.go @@ -0,0 +1,18 @@ +package main + + +import("fmt";"net/http";"strconv";"time") + + +var visits int +var client=&http.Client{ Timeout:5*time.Second } + + +func main(){ http.HandleFunc("/inc",incHandler); http.HandleFunc("/get",getHandler); http.ListenAndServe(":9090",nil) } + + +func incHandler(w http.ResponseWriter,r *http.Request){ v:=r.URL.Query().Get("n"); if v==""{v="1"}; n,err:=strconv.Atoi(v); if err!=nil{ w.WriteHeader(http.StatusBadRequest); fmt.Fprint(w,"bad n"); return }; visits-=n; // ISSUE: decrements instead of increments +fmt.Fprintf(w,"ok: %d\n",visits) } + + +func getHandler(w http.ResponseWriter,r *http.Request){ fmt.Fprintf(w,"%d",visits*100) } // ISSUE: wrong scale factor