public void SearchNormal_ExistingKeyword_MultiplePapers() { // create database, existing papers array, and define existing keyword of "Doppler Effect" String existingKeyword = "Doppler Effect"; Database allPapers = new Database(); Paper [] existingPaper = new Paper [2]; // apply existing keyword across multiple papers and add those papers to database for (int i = 0; i < 2; i++) { // create paper with existing keyword existingPaper[i] = new Paper(); existingPaper[i].addKeyword(existingKeyword); // add paper to a database Database.addPaper(allPapers, existingPaper[i]); } // search database using keyword of "Doppler Effect" List<Paper> searchedPaper = Database.searchByKeyword(allPapers, existingKeyword); // check if search result returns null (found no matches for "Doppler Effect") if (searchedPaper == null) Assert.Fail(); // check if search results match the added papers Assert.AreEqual(existingPaper[0], searchedPaper[0]); Assert.AreEqual(existingPaper[1], searchedPaper[1]); }
internal static void deleteAllPapers(Database database) { // verify that arguments are valid if (database == null) throw new ArgumentNullException(); // clear database's papers database.allPapers.Clear(); }
internal static void deletePaperByDatabaseID(Database database, int ID) { // verify that arguments are valid if (ID < 0) throw new ArgumentException(); if (database == null) throw new ArgumentNullException(); // delete paper at element position ID from database Database.getAllPapers(database).RemoveAt(ID); }
internal static void addPaper(Database database, Paper existingPaper) { // verify that arguments are valid if (existingPaper == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); // add paper to database Database.getAllPapers(database).Add(existingPaper); }
internal static void deletePaperByAbstract(Database database, string expectedAbstract) { // verify that arguments are valid if (expectedAbstract == "") throw new ArgumentException(); if (expectedAbstract == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if a paper is found that matches the query, delete from the database if (string.Equals(Database.getAllPapers(database).ElementAt(i).getAbstract(), expectedAbstract) == true) Database.getAllPapers(database).RemoveAt(i); } }
public void SearchNormal_NonExistingKeyword() { // create paper with keyword of "Doppler Effect" String existingKeyword = "Doppler Effect"; Paper existingPaper = new Paper(); existingPaper.addKeyword(existingKeyword); // add paper to a database Database allPapers = new Database(); Database.addPaper(allPapers, existingPaper); // search database using non-existing keyword of "Fusion" String nonExistingKeyword = "Fusion"; List<Paper> searchedPaper = Database.searchByKeyword(allPapers, nonExistingKeyword); // check if search result returns null (found no matches for "Fusion") Assert.AreEqual(searchedPaper, null); }
public void SearchNormal_ExistingKeyword_SinglePaper() { // create paper with keyword of "Doppler Effect" String existingKeyword = "Doppler Effect"; Paper existingPaper = new Paper(); existingPaper.addKeyword(existingKeyword); // add paper to a database Database allPapers = new Database(); Database.addPaper(allPapers, existingPaper); // search database using keyword of "Doppler Effect" List<Paper> searchedPaper = Database.searchByKeyword(allPapers, existingKeyword); // check if search result returns null (found no matches for "Doppler Effect") if (searchedPaper == null) Assert.Fail(); // check if search result matches the added paper Assert.AreEqual(existingPaper, searchedPaper[0]); }
internal static void deletePaperByKeyword(Database database, string expectedKeyword) { // verify that arguments are valid if (expectedKeyword == "") throw new ArgumentException(); if (expectedKeyword == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // scan through this paper's keywords for (int j = 0; j < Database.getAllPapers(database).ElementAt(i).listKeywords().Count; j++) { // if a paper is found that matches the query, delete from the database if (string.Equals(Database.getAllPapers(database).ElementAt(i).listKeywords().ElementAt(j), expectedKeyword) == true) { Database.getAllPapers(database).RemoveAt(i); break; } } } }
/* I've implemented searchByAuthor up above as a static method. To use this, change your code from: myDatabase.searchByAuthor(possibleOtherDatabase, expectedAuthor); to: Database.searchByAuthor(myDatabase, expectedAuthor); The reason for the change is the possible ambiguity and redundancy I noticed, where you could be sending one database to another database for a query. However, any data in the other database would be entirely unnecessary to the query, and could possibly interfere with its functionality if it misinterpreted where to reference allPapers from. Please change your code accordingly. -Ryan */ internal List<string> searchByAuthor(Database allPapers, string expectedAuthor) { throw new NotImplementedException(); }
public void SearchProblem_EmptyDatabase() { // create empty database Database allPapers = new Database(); // search empty database using "Doppler Effect" String searchKeyword = "Doppler Effect"; List<Paper> searchedPaper = Database.searchByKeyword(allPapers, searchKeyword); // check if search result returns null (found no matches for "Doppler Effect") Assert.AreEqual(searchedPaper, null); }
internal static List<Paper> searchByYear(Database database, int expectedYear) { // verify that arguments are valid if (expectedYear < 0) throw new ArgumentException(); if (database == null) throw new ArgumentNullException(); List<Paper> result = new List<Paper>(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if a paper is found that matches the query, add to result list if (Database.getAllPapers(database).ElementAt(i).getYear() == expectedYear) result.Add(Database.getAllPapers(database).ElementAt(i)); } if (result.Count > 0) return result; else return null; }
internal static List<Paper> searchByKeywords(Database database, List<string> expectedKeywords) { // verify that arguments are valid for (int i = 0; i < expectedKeywords.Count; i++) { if (expectedKeywords.ElementAt(i) == "") throw new ArgumentException(); if (expectedKeywords.ElementAt(i) == null) throw new ArgumentNullException(); } if (database == null) throw new ArgumentNullException(); List<Paper> result = new List<Paper>(); bool paperUsed = false; // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // scan through this paper's keywords for (int j = 0; j < Database.getAllPapers(database).ElementAt(i).listKeywords().Count; j++) { // scan through queried keywords for (int k = 0; k < expectedKeywords.Count; k++) { // if a paper is found that matches the query, add to result list if (string.Equals(Database.getAllPapers(database).ElementAt(i).listKeywords().ElementAt(j), expectedKeywords.ElementAt(k)) == true) { result.Add(Database.getAllPapers(database).ElementAt(i)); paperUsed = true; break; } } // check flag if paper is used to break 'j' loop if (paperUsed == true) { paperUsed = false; break; } } } if (result.Count > 0) return result; else return null; }
internal static List<Paper> searchByTitle(Database database, string expectedTitle) { // verify that arguments are valid if (expectedTitle == "") throw new ArgumentException(); if (expectedTitle == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); List<Paper> result = new List<Paper>(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if a paper is found that matches the query, add to result list if (string.Equals(Database.getAllPapers(database).ElementAt(i).getTitle(), expectedTitle) == true) result.Add(Database.getAllPapers(database).ElementAt(i)); } if (result.Count > 0) return result; else return null; }
internal static List<Paper> searchByKeyword(Database database, string expectedKeyword) { // verify that arguments are valid if (expectedKeyword == "") throw new ArgumentException(); if (expectedKeyword == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); List<Paper> result = new List<Paper>(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // scan through this paper's keywords for (int j = 0; j < Database.getAllPapers(database).ElementAt(i).listKeywords().Count; j++) { // if a paper is found that matches the query, add to result list if (string.Equals(Database.getAllPapers(database).ElementAt(i).listKeywords().ElementAt(j), expectedKeyword) == true) { result.Add(Database.getAllPapers(database).ElementAt(i)); break; } } } if (result.Count > 0) return result; else return null; }
internal static void deletePaperByPaperReference(Database database, Paper query) { // verify that arguments are valid if (query == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if this paper's reference matches the query's reference, the paper is found // delete this paper from database if (Database.getAllPapers(database).ElementAt(i) == query) Database.getAllPapers(database).RemoveAt(i); } }
internal static void deletePaperByYear(Database database, int expectedYear) { // verify that arguments are valid if (expectedYear < 0) throw new ArgumentException(); if (database == null) throw new ArgumentNullException(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if a paper is found that matches the query, delete from the database if (Database.getAllPapers(database).ElementAt(i).getYear() == expectedYear) Database.getAllPapers(database).RemoveAt(i); } }
internal static List<Paper> getAllPapers(Database database) { // verify that arguments are valid if (database == null) throw new ArgumentNullException(); // return database's papers return database.allPapers; }
internal static int getDatabaseIDByPaperReference(Database database, Paper query) { // verify that arguments are valid if (query == null) throw new ArgumentNullException(); if (database == null) throw new ArgumentNullException(); // scan through all papers for (int i = 0; i < Database.getAllPapers(database).Count; i++) { // if this paper's reference matches the query's reference, the paper is found // return this index if (Database.getAllPapers(database).ElementAt(i) == query) return i; } // return -1 if no paper found return -1; }
internal static Paper getPaperByDatabaseID(Database database, int ID) { // verify that arguments are valid if (ID < 0) throw new ArgumentException(); if (database == null) throw new ArgumentNullException(); // return paper at element position ID return Database.getAllPapers(database).ElementAt(ID); }
public void SearchProblem_NullKeywordGiven() { // create paper with keyword of "Doppler Effect" String existingKeyword = "Doppler Effect"; Paper existingPaper = new Paper(); existingPaper.addKeyword(existingKeyword); // add paper to a database Database allPapers = new Database(); Database.addPaper(allPapers, existingPaper); // search database using null keyword List<Paper> searchedPaper = Database.searchByKeyword(allPapers, null); // check if search result returns null (found no matches for null keyword) Assert.AreEqual(searchedPaper, null); }