import unittest
from instrumental_determinator import song_is_vocal

class TestInstrumentalDeterminator(unittest.TestCase):
    
    def test_explicit_instrumental_requests(self):
        """Test inputs that explicitly request instrumental music."""
        instrumental_requests = [
            "create an instrumental beat",
            "make a song without lyrics",
            "generate an instrumental track",
            "I want a backing track with no vocals",
            "create a beat only track",
            "make a piano solo",
            "create lofi beat for studying",
            "generate ambient music",
            "orchestral score for a movie scene",
            "create a wordless melody",
            "I need an instrumental version of a jazz song",
            "produce a track with no singing",
            "make an instrumental that's upbeat for a workout",
            "I want just the music, no vocals at all",
            "create a soundtrack without any words",
            "generate a classical song without lyrics",
        ]
        
        for request in instrumental_requests:
            self.assertFalse(song_is_vocal(request), f"Failed on: '{request}'")
    
    def test_explicit_vocal_requests(self):
        """Test inputs that explicitly request songs with vocals/lyrics."""
        vocal_requests = [
            "write a song with lyrics about love",
            "create a song with vocals about summer",
            "sing about my day at the beach",
            "generate a song with singing",
            "write lyrics about friendship",
            "create a song with a catchy chorus",
            "make me a song that rhymes",
            "need a song with verses about winter",
            "create a song with singing about nature",
            "write a song with a verse and chorus",
            "I want a song where the lyrics talk about my childhood",
            "create vocals for a song about dreams",
            "write a song with words that describe feeling lonely",
            "create a ballad with emotional lyrics",
            "make a song that tells a story about adventure"
        ]
        
        for request in vocal_requests:
            self.assertTrue(song_is_vocal(request), f"Failed on: '{request}'")
    
    def test_ambiguous_requests(self):
        """Test inputs that don't explicitly mention vocals or instrumental."""
        # These should default to vocals (True) since they're descriptive
        ambiguous_requests = [
            "create a happy song",
            "make a song about mountains",
            "generate an upbeat dance track",
            "write a song that makes me cry",
            "create something energetic",
            "make music that reminds me of space",
            "create a jazz tune",
            "I want something peaceful and calming",
            "make a country song",
            "create something that sounds like rain"
        ]
        
        for request in ambiguous_requests:
            self.assertTrue(song_is_vocal(request), f"Failed on: '{request}'")
    
    def test_complex_mixed_signals(self):
        """Test inputs with mixed or complex signals."""
        complex_cases = [
            # Format: (prompt, expected_is_vocal)
            ("I want an instrumental but with some spoken words in the background", True),
            ("Make an instrumental track but not totally without vocals, maybe some oohs and aahs", True),
            ("I don't want an instrumental version, I need lyrics", True),
            ("Not just music, I want singing too", True),
            ("I need a backing track but no vocals please", False),
            ("Give me a piano piece without any singing", False),
            ("Make it not vocal but instrumental instead", False),
            ("Create a soundtrack that isn't vocal", False),
            ("I want a song with no lyrics that has a strong melody", False),
            ("No vocal track, just the instrumental please", False),
            ("I want a song with no lyrics that has a strong melody", False),
            ("No vocal track, just the instrumental please", False)
        ]
        
        for prompt, expected in complex_cases:
            result = song_is_vocal(prompt)
            self.assertEqual(result, expected, f"Failed on complex case: '{prompt}'")
    
    def test_longer_prompts(self):
        """Test with longer, more realistic prompts."""
        longer_prompts = [
            # Format: (prompt, expected_is_vocal)
            ("I want a song that captures the feeling of driving down the highway on a warm summer evening, with the windows down and the wind in my hair. Something that reminds me of freedom and youth.", True),
            
            ("Create an instrumental piece that evokes the feeling of wandering through an ancient forest. It should start quietly, build to a climax with string instruments, and then fade out with gentle piano notes.", False),
            
            ("Write me a song about falling in love with someone unexpected. It should have a gentle verse and a powerful chorus that captures the surprise and joy of new love.", True),
            
            ("I need background music for a documentary about space exploration. It should be mostly ambient with no distracting vocals, just pure cosmic sounds that complement the visuals.", False),
            
            ("Create a song that tells the story of someone overcoming great obstacles in their life. I want it to be inspirational and have meaningful words that people can relate to when facing their own challenges.", True)
        ]
        
        for prompt, expected in longer_prompts:
            result = song_is_vocal(prompt)
            self.assertEqual(result, expected, f"Failed on longer prompt case: '{prompt}'")

    def test_very_long_prompts(self):
        """Test with very long prompts (around 2000 characters)."""
        very_long_prompts = [
            # Format: (prompt, expected_is_vocal)
            
            # Long vocal prompt (storytelling song)
            ("""I want a song that tells an epic story about a traveler who journeys across different landscapes and meets various characters along the way, each teaching them something important about life. The song should start with the traveler feeling lost and uncertain about their path, standing at a crossroads not knowing which way to turn. In the first verse, they meet an old fisherman by a misty lake who teaches them patience and how to find beauty in stillness. The chorus should be about how life is a winding road with unexpected turns, but each step brings new wisdom. In the second verse, they encounter a young artist in a bustling city who shows them how to see color and possibility in chaos. Then the chorus repeats. In the third verse, they meet a child in a meadow who reminds them of the joy of simple things and the importance of play. After the chorus again, there's a bridge where the traveler climbs a mountain and has a moment of clarity, realizing that the journey itself was the destination all along. The final chorus should be more triumphant, with the traveler now embracing uncertainty as opportunity. The song should end with them setting off towards a new horizon, wiser from all they've experienced. I'd like the melody to start somewhat melancholic but gradually become more uplifting as the traveler gains confidence. The instrumentation should reflect the different environments - perhaps gentle acoustic guitar for the lake, more complex arrangements for the city, light and playful for the meadow, and something grand and expansive for the mountain scene. I want the lyrics to be poetic but accessible, with vivid imagery that brings these scenes and characters to life. The overall message should be about finding wisdom in unexpected places and growing through experience.""", True),
            
            # Long instrumental prompt
            ("""I'm looking for an instrumental piece that evokes the feeling of exploring an ancient, abandoned temple hidden deep in a rainforest. The composition should begin very quietly with subtle, distant sounds of wildlife and gentle wind that gradually fade in. Then introduce a soft, mysterious melody on a wooden flute that feels like it's calling the listener deeper into the temple. As the piece progresses, I want the listener to feel like they're moving through different chambers of this forgotten place. In the second movement, add deeper percussion elements - perhaps some tribal drums that start softly but build in intensity, suggesting the temple is slowly awakening to the presence of an explorer. Mix in some string elements that create tension and wonder. For the third section, introduce some metallic sounds, like subtle chimes or singing bowls, that suggest the discovery of sacred artifacts or ancient mechanisms coming to life. This section should feel like the heart of the temple, where the most important discoveries are made. The percussion should become more complex here, with intricate rhythms that seem to echo through stone corridors. In the fourth movement, everything should build to a climactic revelation - as if the explorer has reached the central chamber and witnessed something extraordinary. Use broad, sweeping orchestral elements here, perhaps with some synthetic sounds that give an otherworldly feeling. Then, for the final section, the music should gradually become calmer and more reflective, as if the explorer is leaving the temple with new knowledge and reverence. End with just the flute melody from the beginning and the ambient jungle sounds, bringing the journey full circle. Throughout the piece, I want no vocals or lyrics whatsoever - this should be purely instrumental to allow the listener to create their own mental imagery. The overall length should be about 5-6 minutes, giving enough time for this musical journey to unfold naturally. The feeling should be mysterious, awe-inspiring, and slightly mystical, but not scary or threatening.""", False),
        ]
        
        for prompt, expected in very_long_prompts:
            result = song_is_vocal(prompt)
            self.assertEqual(result, expected, 
                            f"Failed on very long prompt. Expected: {expected}, Got: {result}. Prompt length: {len(prompt)}")

    def test_additional_prompts(self):
        """Test a variety of additional prompts with different contexts."""
        additional_prompts = [
            # Format: (prompt, expected_is_vocal)
            ("I want a song about the sunrise over the mountains with a peaceful atmosphere.", True),
            ("Create an ambient track that sounds like underwater exploration.", False),
            ("Make a soundtrack for studying that isn't distracting.", False),
            ("I need music for a meditation session.", False),
            ("Write a lullaby about dreams and stars.", True),
            ("Compose a piano piece that evokes falling snow.", False),
            ("Generate some lofi hip hop.", True),  
            ("Create music that sounds like a busy marketplace.", True),
            ("I want a song that expresses the feeling of freedom.", True),
            ("Make me a track with heavy bass and drums.", True)
        ]
        
        for prompt, expected in additional_prompts:
            result = song_is_vocal(prompt)
            self.assertEqual(result, expected, f"Failed on additional prompt: '{prompt}'")

    def test_real_world_prompts(self):
        """Test with a large collection of real-world user prompts."""
        
        # Most of these prompts explicitly or implicitly request vocals (songs about topics)
        vocal_prompts = [
            "create a song about seattle rain",
            "create song about having headache, cough, and fever",
            "create a song on Suno for my best friend Himanshu who is sleeping for India",
            "create song about cats",
            "create a song about cats",
            "create alexa",
            "create a song about stars in space",
            "create a song about space",
            "create a song about cartoon",
            "create a lizard birthday song",
            "create a song about the hot day today",
            "create a song about television",
            "create a song about gadgets based on The Glow Box Dream",
            "create a song about butterflies",
            "create a song about legos",
            "create a song about a kangaroo's bar mitzvah",
            "create a hip hop song for my niece's fifth birthday",
            "create a k. pop song for my son's fifteenth birthday",
            "create a song about tuesday busy day",
            "create a hip hop song for my niece's fifth birthday",
            "create a song about tuesday morning meetings",
            "create a funk rock song about dad's birthday tomorrow",
            "Create a funk rock song about dad's birthday tomorrow",
            "create a fun rock song about dad's birthday tomorrow",
            "create a song about birds and butterflies",
            "create a song about chocolates",
            "create song about coughing whole day",
            "generate song about chocolates",
            "create song about cars",
            "create song about dogs",
            "create song about chocolates",
            "play my song about the banjo man from suno",
            "play my banjo man song from suno",
            "play my existing song called banjo man from suno",
            "create a song about a banjo player",
            "play my song The Banjo Man from Suno",
            "create a song about tuesday morning drive",
            "create a song about movie nights",
            "create a jazz song about living life",
            "create a song about leaning tower of pisa",
            "create a song about discovering new things",
            "create music about sun",
            "modify Beta Feedback Groove about beta survey in pop music with title 23 Beta",
            "modify Beta Feedback Groove about beta survey",
            "create song about beta survey",
            "modify Beta Feedback Groove about beta survey in country music",
            "create a song about being sick",
            "create a song about politics",
            "create a song about best places to see in seattle",
            "create a song about a relentless cat",
            "play Seattle Wonders from suno",
            "create a song about a lizard's anniversary",
            "create a song about a brave kangaroo",
            "play my suno song titled brave kangaroo",
            "play song about renewable energy",
            "create a song about monday morning blues",
            "create a song on Suno for a birthday party",
            "create a song on Suno for Manchester United football club",
            "create a song about Manchester United on Suno",
            "create song about mist and feeling cold",
            "create a song about eminem",
            "create a song about electric pumps",
            "create a song similar to coldplay",
            "create a song about mt st helens erupting in the 1980s",
            "create a song about an iphone",
            "create a song about water",
            "create a song about colors in butterflies",
            "create a song about dogs",
            "create a song about my cat with more rap style",
            "create a song about a smart cat",
            "create a song about a tired leopard",
            "create a song",
            "create a song with music about travel",
            "create song about new york city",
            "create a song about the fisherman from Seattle",
            "create a song about the game of thrones dragon",
            "create a song for butterflies",
            "modify song in pop music",
            "create new song in Telugu about Abhay",
            "create song about chocolates",
            "create song about Abhay",
            "modify Chocolate Bliss song to include my son",
            "create a song about legos",
            "build a song about legos",
            "create a song about tuesdays",
            "create a song about blueberries",
            "create a song about monday morning",
            "create a song about monster",
            "create a song about party",
            "create a song about happiness",
            "create a song about a lizard's bar mitzvah",
            "create a pop song",
            "create a track about farm animals",
            "create a song about love",
            "create a jazz song",
            "create song about hot sun",
            "start a song about bus",
            "create a song about movies",
            "create a song about Statue of Liberty",
            "create a song about sunny day in seattle",
            "create a song about a boring elephant",
            "create a song about a hungry panther",
            "create a song about a relentless cat",
            "create a song on summer",
            "create a country music song about summer",
            "create a song chocolate bliss including cookie",
            "create a song about dogs",
            "create a song about space",
            "create a song about television",
            "create a song about monster",
            "create a song about butterflies",
            "create a song more about the stars in the song which i created for space",
            "create a song about cartoon",
            "create a song about my cat",
            "create a song about a lizard's anniversary",
            "create a song about lunch time",
            "create a song about Seattle",
            "create song about dogs",
            "create a song about books",
            "create a k. pop song about my friend",
            "create a song about tomorrow",
            "create a song about a fearless cat",
            "play the song i created about dogs",
            "create a song about animals and cats",
            "create a song about cars",
            "create a song about love",
            "create a song about dogs",
            "create a song",
            "create an electric pop song",
            "create a song about eminem",
            "modify the song Chocolate Dreams",
            "create a song about seattle summers",
            "create a song about unicorns in the laptop from study female list",
            "create a song about electric pops",
            "create a song about electric bulbs",
            "create an electric pop song",
            "create a song similar to adele",
            "create a song about petta survivor twenty three",
            "create a song about my son",
            "create a song about violence",
            "create a song about blueberries",
            "create a song about chocolates",
            "generate a song about chocolates",
            "generate song about chocolates",
            "create a new song about my love for travel",
            "create a song about may gloom",
            "create a song about may gloom",
            "create a song about sky in space",
            "play the song I created today about sky in space",
            "create a country song dedicated to Christina about love and diamond painting",
            "create a song about leaning tower of pisa",
            "create a song about a donkey",
            "create a song about an elephant",
            "create a song about cats",
            "create a song about butterflies",
            "create a song about a cat",
            "create a song about a tiny tiger",
            "create a song about a donkey",
            "create a song about a tiger",
            "create a song about a cat",
            "create a song about a tiger",
            "create a song about a tiger",
            "create a song about giraffe",
            "create a song about green juice for lunch",
            "create a song about recent events",
            "create a song about movies",
            "create a song about my love for travel",
            "create a song about cats",
            "create song about butterflies",
            "create songs about violence and sex",
            "create a song about love",
            "create reluctant love song about bodyjaw cats",
            "create songs about violence and sex",
            "create a song about legos"
        ]
        
        # These prompts seem more likely to be requesting instrumental tracks
        instrumental_prompts = [
            "generate a chill ambient vibes track for working",
            "create a piano instrumental song",
            # Generic "create a song" without topic could be either, but the algorithm should default to vocals
        ]
        
        # Test all vocal prompts
        for prompt in vocal_prompts:
            result = song_is_vocal(prompt)
            self.assertTrue(result, f"Failed on vocal prompt: '{prompt}'")
        
        # Test all instrumental prompts
        for prompt in instrumental_prompts:
            result = song_is_vocal(prompt)
            self.assertFalse(result, f"Failed on instrumental prompt: '{prompt}'")

if __name__ == "__main__":
    unittest.main()
